跳至內容

Fn::GetAZs returns fewer AZs than expected

0

The below Cloudformation fails for certain regions and succeeds in others.

Resources:
  SourceSQLVPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.150.0.0/16
  SourceSubnet3:
    Type: AWS::EC2::Subnet
    Properties:
      VpcId: !Ref SourceSQLVPC
      CidrBlock: 10.150.15.0/24
      AvailabilityZone:
        Fn::Select:
        - 2
        - Fn::GetAZs: "us-east-1"

已提問 2 年前檢視次數 274 次

2 個答案
1

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:

  1. Use a parameter to specify the AZ explicitly, allowing more control over AZ selection.

  2. Implement error handling in your template to account for cases where fewer than three AZs are available.

  3. 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.

  4. 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.

  5. 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

已回答 2 年前

專家

已審閱 2 年前

0
已接受的答案

Fn:getAZs only returns AZs that have a default subnet in your default VPC. You might need to create default subnets in additional AZs.

已回答 2 年前

專家

已審閱 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。