简体   繁体   中英

How to use StringList value of AWS SSM in cloudformation template

I have stored two subnets in aws ssm whose datatype is StringList like this s1,s2 and in lambda function I want to attach these two subnets using cloudformation template. Lambda function will put the data to postgres database so for that I need to attch these subnets.

AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"

Resources:
  ExportToS3Function:
    Type: AWS::Serverless::Function 
    Properties:
      FunctionName: testing-ssm
      CodeUri: testing-ssm/
      Environment:
        Variables:
          RDS_SECRET: XXXXXXX
          REGION: !Sub "${AWS::Region}"
      Handler: lambda_function.lambda_handler
      Runtime: python3.8
      Timeout: 600
      MemorySize: 1750
      VpcConfig:
        SecurityGroupIds:
          - '{{resolve:ssm:/testing/vpc/sg:1}}'
        SubnetIds: !Split [',','{{resolve:ssm:/testing/vpc/subnets:1}}']
      Role: !GetAtt testing-ssm.Arn

But above line,Split [',':'{{resolve:ssm:/testing/vpc/subnets:1}}'] giving me an error while deploying

Resource handler returned message: "1 validation error detected: Value '[subnet-XXXXX, subnet-XXXXXX]' at 'vpcConfig.subnetIds' failed to satisfy constraint

SSM needs to be a string type regardless of the type specified. Type is metadata for the client only. So if you have an array, you need to do ssm_list -> value = join(", ", subnet_ips_list) when terraforming this SSM. Inside the template, you can reference it as Type: 'AWS::SSM::Parameter::Value<CommaDelimitedList>' and you can pass an array straight after SubnetIds: ssm_list

or one by one

SubnetIds:
  - !Select [0, !Split [ ", ", ssm_list ]]

maybe those will help as well: How can I store a three element tuple in AWS SSM parameter with Terraform?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM