Is there a way for cloudformation to query available zones for subnet creation?

amazon-web-services, availability-zone, aws-cloudformation

Solution

This may not be helpful for the CLI Approach or your exact scenario - but with AWS Management Console this works smooth.

With the recent updates with the CloudFormation Parameters, you would be able pin-point the AZs pertaining to the specified AZs.

This would be much convenient during the DR / DR Drills and making the CFN template Region Independent.

"Parameters": {
    "SubnetAZ": {
      "Description": "Availability Zone of the Subnet",
      "Type": "AWS::EC2::AvailabilityZone::Name"
    }
}

More Information About the CloudFormation Parameters

Problem

I have a cloudformation script that attempts to create a VPC, with one subnet per AZ. When I run: ``` aws ec2 describe-availablity-zones ``` I get 4 zones returned: ``` "AvailabilityZones": [ { "State": "available", "RegionName": "us-east-1", "Messages": [], "ZoneName": "us-east-1a" }, { "State": "available", "RegionName": "us-east-1", "Messages": [], "ZoneName": "us-east-1b" }, { "State": "available", "RegionName": "us-east-1", "Messages": [], "ZoneName": "us-east-1c" }, { "State": "available", "RegionName": "us-east-1", "Messages": [], "ZoneName": "us-east-1d" } ] ``` However, when I try to create my stack, I get an error: ``` "ResourceStatusReason": "Value (us-east-1a) for parameter availabilityZone is invalid. Subnets can currently only be created in the following availability zones: us-east-1c, us-east-1b, us-east-1d.", ``` I am specifying the AZ with ``` "AvailabilityZone" : { "Fn::Select" : [ "0", { "Fn::GetAZs" : "" } ] }, ``` Is there a way to check to see if the AZ is really available for the creation of a subnet?

Original source