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

已提問 3 個月前檢視次數 218 次
1 個回答
1
已接受的答案

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
專家
kentrad
已回答 3 個月前
  • 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

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南