

This is the new *CloudFormation Template Reference Guide*. Please update your bookmarks and links. For help getting started with CloudFormation, see the [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html).

# `Fn::GetAZs`
<a name="intrinsic-function-reference-getavailabilityzones"></a>

The intrinsic function `Fn::GetAZs` returns an array that lists Availability Zones for a specified Region in alphabetical order. Because customers have access to different Availability Zones, the intrinsic function `Fn::GetAZs` enables template authors to write templates that adapt to the calling user's access. That way you don't have to hard-code a full list of Availability Zones for a specified Region.

**Important**  
The `Fn::GetAZs` function returns only Availability Zones that have a default subnet unless none of the Availability Zones has a default subnet; in that case, all Availability Zones are returned.  
Similarly to the response from the `describe-availability-zones` AWS CLI command, the order of the results from the `Fn::GetAZs` function isn't guaranteed and can change when new Availability Zones are added.

IAM permissions

The permissions that you need in order to use the `Fn::GetAZs` function depend on the platform in which you're launching Amazon EC2 instances. For both platforms, you need permissions to the Amazon EC2 `DescribeAvailabilityZones` and `DescribeAccountAttributes` actions. For EC2-VPC, you also need permissions to the Amazon EC2 `DescribeSubnets` action.

## Declaration
<a name="intrinsic-function-reference-getazs-declaration"></a>

### JSON
<a name="intrinsic-function-reference-getazs-syntax.json"></a>

```
{ "Fn::GetAZs" : "region" }
```

### YAML
<a name="intrinsic-function-reference-getazs-syntax.yaml"></a>

Syntax for the full function name:

```
Fn::GetAZs: region
```

Syntax for the short form:

```
!GetAZs region
```

## Parameters
<a name="intrinsic-function-reference-getazs-parameters"></a>

region  <a name="region"></a>
The name of the Region for which you want to get the Availability Zones.  
You can use the `AWS::Region` pseudo parameter to specify the Region in which the stack is created. Specifying an empty string is equivalent to specifying `AWS::Region`.

## Return value
<a name="intrinsic-function-reference-getazs-return-value"></a>

The list of Availability Zones for the Region.

## Examples
<a name="intrinsic-function-reference-getazs-examples"></a>

### Evaluate a Region
<a name="intrinsic-function-reference-getazs-examples-evaluate-region"></a>

For these examples, CloudFormation evaluates `Fn::GetAZs` to the following array—assuming that the user has created the stack in the `us-east-1` Region:

`[ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e" ]`

#### JSON
<a name="intrinsic-function-reference-getazs-example1.json"></a>

```
1. { "Fn::GetAZs" : "" }
2. { "Fn::GetAZs" : { "Ref" : "AWS::Region" } }
3. { "Fn::GetAZs" : "us-east-1" }
```

#### YAML
<a name="intrinsic-function-reference-getazs-example1.yaml"></a>

```
1. Fn::GetAZs: ""
2. Fn::GetAZs:
3.   Ref: "AWS::Region"
4. Fn::GetAZs: us-east-1
```

 

### Specify a subnet's Availability Zone
<a name="intrinsic-function-reference-getazs-examples-subnet-az"></a>

The following example uses `Fn::GetAZs` to specify a subnet's Availability Zone:

#### JSON
<a name="intrinsic-function-reference-getazs-example.json"></a>

```
"mySubnet" : {
  "Type" : "AWS::EC2::Subnet",
  "Properties" : {
    "VpcId" : { 
      "Ref" : "VPC"   
    },
    "CidrBlock" : "10.0.0.0/24",
    "AvailabilityZone" : {
      "Fn::Select" : [ 
        0, 
        { 
          "Fn::GetAZs" : "" 
        } 
      ]
    }
  }
}
```

#### YAML
<a name="intrinsic-function-reference-getazs-example.yaml"></a>

```
mySubnet: 
  Type: AWS::EC2::Subnet
  Properties: 
    VpcId: 
      !Ref VPC
    CidrBlock: 10.0.0.0/24
    AvailabilityZone: 
      Fn::Select: 
        - 0
        - Fn::GetAZs: ""
```

 

### Nested functions with short form YAML
<a name="intrinsic-function-reference-getazs-examples-nested-functions"></a>

The following examples show valid patterns for using nested intrinsic functions using short form YAML. You can't nest short form functions consecutively, so a pattern like `!GetAZs !Ref` isn't valid.

#### YAML
<a name="intrinsic-function-reference-getavailabilityzones-example3.yaml"></a>

```
1. AvailabilityZone: !Select
2.   - 0
3.   - !GetAZs
4.     Ref: 'AWS::Region'
```

#### YAML
<a name="intrinsic-function-reference-getavailabilityzones-example4.yaml"></a>

```
1. AvailabilityZone: !Select
2.   - 0
3.   - Fn::GetAZs: !Ref 'AWS::Region'
```

## Supported functions
<a name="intrinsic-function-reference-getazs-supported-functions"></a>

You can use the `Ref` function in the `Fn::GetAZs` function.