1

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

flzzz
  • 553
  • 1
  • 4
  • 20
Raghav
  • 19
  • 1
  • 6
  • You have to provide more details. E.g. Complete template? How to reproduce your issue? Step by step? – Marcin Aug 17 '22 at 06:59
  • @Marcin i have edited the question please go through it. I have gone through almost every documentation and StackOverflow but can not find related answer. My subnets are stored as StringList datatype in was ssm and I want them to use in cft – Raghav Aug 17 '22 at 07:15
  • Did you try with `SubnetIds: ['{{resolve:ssm:/testing/vpc/subnets:1}}']`? – Marcin Aug 17 '22 at 07:31
  • Not working same error occured. – Raghav Aug 17 '22 at 14:21

1 Answers1

0

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?