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

preguntada hace 3 meses218 visualizaciones
1 Respuesta
1
Respuesta aceptada

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
EXPERTO
kentrad
respondido hace 3 meses
  • 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

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas