내용으로 건너뛰기

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년 전273회 조회

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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

관련 콘텐츠