Create DBSubnetGroup SubnetIds from ASW::EC2::Subnet:Id in CloudFormation

0

I am trying to create an Aurora MySQL RDS using CloudFormation. The code below is just a snippet of what it is doing. The issue I am having is that the SubnetIds for the DBSubnetGroup is not accepting what is being passed. It either errors out with receiving jsonarray instead of string. Or receiving jsonobject instead of jsonarray. Has anyone worked on this?

AWSTemplateFormatVersion: "2010-09-09"
Metadata:
  AWS::CloudFormation::Interface: 
      ParameterGroups: 
      - 
        Label: 
          default: "Network Configuration"
        Parameters:
          - MainRegion
          - ClusterPrefix
          - VPCName
          - VPCSecurityGroupIds
          - SelectedSubnetIds

Parameters:

  MainRegion:
    Type: String
    Default: us-west-2
    AllowedValues:
      - us-east-1
      - us-east-2
      - us-west-1
      - us-west-2      
    Description: Select the main region of choice.

  ClusterPrefix:
    Description: Enter (in lowercase) the cluster prefix that will be added to the begining of the RDS resource
    Type: String
    Default: abc

  VPCName:
    Description: Select the VPC for the RDS Aurora MySQL
    Type: AWS::EC2::VPC::Id

  VPCSecurityGroupIds:
    Description: Select the VPC Security Group
    Type: "List<AWS::EC2::SecurityGroup::Id>"

  SelectedSubnetIds:
    Description: Select the subnets
    Type: "List<AWS::EC2::Subnet::Id>"


Resources:

    RDSDBSubnetGroup:
        Type: "AWS::RDS::DBSubnetGroup"
        Properties:
            DBSubnetGroupDescription: "Subnet Group for Name Global DB"
            DBSubnetGroupName: "${ClusterPrefix}-name-db-sg"
            SubnetIds: 
               - !Ref SelectedSubnetIds
              #[ SelectedSubnetIds ]
              #'!ForEach::SelectValue':
              #  - SelectedSubnet
              #  - !Ref SelectedSubnetIds
                #- SelectedSubnet
                #- !Ref 'Fn::Sub': '${SelectedSubnet}'
                #- !Join [ ",", [ SelectedSubnet ] ]
               # - Fn::ToJsonString SelectedSubnet
                #- ListOutput: true

1 Answer
1
Accepted Answer

Have you tried:

    RDSDBSubnetGroup:
        Type: "AWS::RDS::DBSubnetGroup"
        Properties:
            DBSubnetGroupDescription: "Subnet Group for Name Global DB"
            DBSubnetGroupName: "${ClusterPrefix}-name-db-sg"
            SubnetIds: !Ref SelectedSubnetIds

I suspect the "-" is saying it is an element of an array instead of the just the array.

profile pictureAWS
EXPERT
kentrad
answered 3 months ago
  • I've tried many ways and I believe that was one of them. However, it does produce a different error.

    Properties validation failed for resource RDSDBSubnetGroup with message: #/DBSubnetGroupName: failed validation constraint for keyword [pattern]

  • Thank you very much. Obviously, I never tried that one because after that the naming convention was simple. Thank you again kentrad

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions