how to construct a string of physical subnet ids to create db subnet group on the fly in a cloudformation script?

StackOverflow https://stackoverflow.com/questions/16909055

문제

I'm trying to build a CLoudFormation script that launches an instance and a db into a vpc at the same time. the issue is the db requires two AZ's so i create a second subnet and now i just need to reference the two subnet physical ids in a 'MyDBSubnetGroup' var. I can get the logical IDs for the subnets i created but dont know how to ref those physical IDs. ANyone know? THanks!!

Heres my code:

"MyDBSubnetGroup" : {
      "Type" : "AWS::RDS::DBSubnetGroup",
      "Properties" : {
        "DBSubnetGroupDescription" : "Subnets available for the RDS DB Instance",
        "SubnetIds" : { "Fn::Join" : [ " ", [{"Ref" : "PublicSubnetAZ1"}, ", ", {"Ref" : "PublicSubnetAZ2"}, " " ]]}
      }
    },
도움이 되었습니까?

해결책

I run into the same issue, after working with AWS support I understood that List of String does not mean what we initially thought. Also, if you want to place the DB inside a VPC you must not use AWS::RDS::DBSecurityGroup objects.

Here is a full sample, it took me a while to get it working:

"dbSubnetGroup" : {
        "Type" : "AWS::RDS::DBSubnetGroup",
        "Properties" : {
            "DBSubnetGroupDescription" : "Availability Zones for RDS DB",
            "SubnetIds" : [ { "Ref" : "subnetPrivate1" },
                            { "Ref" : "subnetPrivate2" } ]
        }
},
"dbInstance" : {
        "Type" : "AWS::RDS::DBInstance",
        "Properties" : {
            "DBInstanceIdentifier" : { "Fn::Join" : [ "",
                                                    [ { "Ref" : "AWS::StackName" },
                                                      "DB" ] ] },
            "DBName" : "dbname",
            "DBSubnetGroupName" : { "Ref" : "dbSubnetGroup" },
            "MultiAZ" : "true",
            "AllocatedStorage" : "8",
            "BackupRetentionPeriod" : "0",
            "DBInstanceClass" : "db.m1.medium",
            "Engine" : "postgres",
            "MasterUserPassword" : "masteruserpassword",
            "MasterUsername" : "masterusername",
            "VPCSecurityGroups" : [ { "Ref" : "sgVpc" }, { "Ref" : "sgDB" } ]
     }
},

다른 팁

If you map the subnet ids you can access them with something like this.

        "AWSRegionSubnet":{
        "us-east-1":{
            "RDSSubnets":[
                "subnet-aaaaaaaa",
                "subnet-bbbbbbbb"
            ]

        },
        "us-west-2":{
            "RDSSubnets":[
                "subnet-cccccccc",
                "subnet-dddddddd"
            ]
        }
    }

        "RDSSubnet":{
        "Type":"AWS::RDS::DBSubnetGroup",
        "Properties":{
            "DBSubnetGroupDescription":"Some cool notes here",
            "SubnetIds":{
                "Fn::FindInMap":[
                    "AWSRegionSubnet",
                    {
                        "Ref":"AWS::Region"
                    },
                    "RDSSubnets"
                ]
            }
        }
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top