- Newest
- Most votes
- Most comments
The issue you're experiencing with Fn::GetAZs returning fewer Availability Zones (AZs) than expected in certain regions is a known behavior in AWS CloudFormation. This function doesn't always return all available AZs in a region, but rather returns a subset based on your account and region.
In some cases, especially for newer AWS accounts or in certain regions, Fn::GetAZs might return fewer than three AZs, causing the template to fail when trying to select the third AZ (index 2).
To address this, you have a few options:
-
Use a parameter to specify the AZ explicitly, allowing more control over AZ selection.
-
Implement error handling in your template to account for cases where fewer than three AZs are available.
-
Use the AWS CLI or SDK to retrieve all available AZs in the region before creating the stack, and then pass these as parameters to your CloudFormation template.
-
For the specific case of us-east-1, you could hardcode the AZ names, as this region typically has six AZs (a through f). However, this approach is less flexible and not recommended for portable templates.
-
Create default subnets in the desired AZs if they don't already exist. This can sometimes increase the number of AZs returned by Fn::GetAZs.
Remember that the availability of AZs can vary based on your AWS account, the specific region, and potentially other factors. It's always a good practice to design your templates to be flexible and handle varying numbers of available AZs.
Sources
can not run this cloudform at my account in region us-east-1 | AWS re:Post
Datazone CloudFormation Region Enablement Error In Env Blueprint Configuration | AWS re:Post
Cloudformation: setting Availability Zone in target group creation | AWS re:Post
Fn:getAZs only returns AZs that have a default subnet in your default VPC. You might need to create default subnets in additional AZs.
Relevant content
asked 10 months ago
