All Products
Search
Document Center

Resource Orchestration Service:Fn::GetAZs

Last Updated:Mar 15, 2024

The built-in function Fn::GetAZs returns a list of zones that belong to a region.

Note

This function is suitable only for Elastic Compute Service (ECS) and Virtual Private Cloud (VPC) resources.

Declaration

  • JSON

    {
     "Fn::GetAZs": "regionId"
    }
  • YAML

    • Syntax for the full function name:

      Fn::GetAZs: regionId
    • Syntax for the short form:

      !GetAZs regionId

Parameters

regionId: the region ID. Example: cn-hangzhou.

Return value

The list of zones in the specified region.

Examples

In the following examples, an ECS instance is created in the first zone of a specified region:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: centos7u2_64_40G_cloudinit_2016072****
      InstanceType: ecs.n1.tiny
      SecurityGroupId: sg-2zedcm7ep5quses0****
      Password: Ros1****
      AllocatePublicIP: true
      InternetChargeType: PayByTraffic
      InternetMaxBandwidthIn: 100
      InternetMaxBandwidthOut: 100
      SystemDiskCategory: cloud_efficiency
      IoOptimized: optimized
      ZoneId:
        !Select
          - '0'
          - !GetAZs
              Ref: ALIYUN::Region
Outputs:
  InstanceId:
    Value: !GetAtt WebServer.InstanceId
  PublicIp:
    Value: !GetAtt WebServer.PublicIp
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Resources": {
    "WebServer": {
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "ImageId": "centos7u2_64_40G_cloudinit_2016072****",
        "InstanceType": "ecs.n1.tiny",
        "SecurityGroupId": "sg-2zedcm7ep5quses0****",
        "Password": "Ros1****",
        "AllocatePublicIP": true,
        "InternetChargeType": "PayByTraffic",
        "InternetMaxBandwidthIn": 100,
        "InternetMaxBandwidthOut": 100,
        "SystemDiskCategory": "cloud_efficiency",
        "IoOptimized": "optimized",
        "ZoneId": {
          "Fn::Select": [
            "0",
            {
              "Fn::GetAZs": {
                "Ref": "ALIYUN::Region"
              }
            }
          ]
        }
      }
    }
  },
  "Outputs": {
    "InstanceId": {
      "Value": {
        "Fn::GetAtt": [
          "WebServer",
          "InstanceId"
        ]
      }
    },
    "PublicIp": {
      "Value": {
        "Fn::GetAtt": [
          "WebServer",
          "PublicIp"
        ]
      }
    }
  }
}

Supported functions