AWS CloudFormation template EC2 – Return Subnet List based on VPC Selection

Viewed 377

I have a CloudFormation Template that stands up EC2 instances. I have sections under parameters and mappings for VPC, Subnet and Security Group. The VPC selection is first but once that VPC selection is made it still presents me with a list of all subnets rather than just the subnets associated with that VPC. If I stand up and EC2 instance via the console and I select the VPC the subnet selection list is narrowed down to only those subnets associated with that VPC. How do I get my Cloud Formation template to do the same? I’m providing the relevant parameter and mappings section of the JSON template below.

        "VpcName": {
            "Description": "Select the VPC for this EC2 Instances",
            "Type": "AWS::EC2::VPC::Id"
        },
        "SubnetID": {
            "Description": "The list of Subnet IDs",
            "Type": "AWS::EC2::Subnet::Id"
        },
        "SecurityGroupIds": {
            "Description": "Specify Security Group",
            "Type": "List<AWS::EC2::SecurityGroup::Id>"
                },
                "VpcName":  {
                    "Ref": "VpcName"
                },
                "SubnetID": {
                    "Ref": "SubnetID"
                },
                "SecurityGroupIds": {
                    "Ref": "SecurityGroupIds"
0 Answers
Related