Home > Net >  AWS Cloudformation Value of property SubnetIds must be of type List of String
AWS Cloudformation Value of property SubnetIds must be of type List of String

Time:10-19

I am tying this cloudformation stack but when creation reaches DBSubnetGroup it fails with the message: Value of property SubnetIds must be of type List of String. I appreciate your help. All seems working fine except the DBSubnetGroup.

AWSTemplateFormatVersion: 2010-09-09
Description: My First CloudFormation Template
Resources:
  MyVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.1.0.0/16
      EnableDnsHostnames: true
      EnableDnsSupport: true
      InstanceTenancy: default
      Tags:
      - Key: Name
        Value: VPC for Activity Number 1 
  MySubnet:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.1.1.0/24
      MapPublicIpOnLaunch: true
      AvailabilityZone: "us-east-1c"
      Tags:
      - Key: Name
        Value: Public Subnet 
  MySubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.1.2.0/24
      MapPublicIpOnLaunch: true
      AvailabilityZone: "us-east-1a"
      Tags:
      - Key: Name
        Value: Public Subnet  A
  MySubnetB:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref MyVPC
      CidrBlock: 10.1.3.0/24
      MapPublicIpOnLaunch: true
      AvailabilityZone: "us-east-1b"
      Tags:
      - Key: Name
        Value: Public Subnet B      

That's where creation failure starts:

  DBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    DependsOn:
      - MyVPC
      - MySubnet
      - MySubnetA
      - MySubnetB
    Properties:
      DBSubnetGroupDescription: Subnets to lauch the database
      SubnetIds: 
        -!Ref MySubnet
        -!Ref MySubnetA  
        -!Ref MySubnetB    
        
      

CodePudding user response:

You should have a space between - and the intrinsic function !Ref in order to be parsed correctly. Sadly, CloudFormation detects this only when the stack is created.

 DBSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    DependsOn:
      - MyVPC
      - MySubnet
      - MySubnetA
      - MySubnetB
    Properties:
      DBSubnetGroupDescription: Subnets to lauch the database
      SubnetIds: 
        - !Ref MySubnet
        - !Ref MySubnetA  
        - !Ref MySubnetB
  • Related