Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (5.6k points)

I want to know the Availability Zone ID using either AWS CLI or using boto3 but can't get it.

aws ec2 describe-subnets --region us-east-1

{

        "VpcId": "vpc-054c741523f481755",

        "CidrBlock": "10.150.3.32/27",

        "MapPublicIpOnLaunch": false,

        "State": "available",

        "Ipv6CidrBlockAssociationSet": [],

        "AssignIpv6AddressOnCreation": false,

        "SubnetId": "subnet-0a36ed4643fb511d1",

        "AvailabilityZone": "us-east-1a",

        "DefaultForAz": false,

        "AvailableIpAddressCount": 27,

        "Tags": [

            {

                "Key": "aws:cloudformation:stack-id",

                "Value": "arn:aws:cloudformation:us-east-1:186940489315:stack/dantooine-a-elastic-subnets/dc3f7500-7b39-11ea-a67d-0e763951b664"

            },

            {

                "Key": "aws:cloudformation:stack-name",

                "Value": "dantooine-a-elastic-subnets"

            },

            {

                "Key": "Name",

                "Value": "dantooine-a-elastic-subnets-endpointSubnet"

            },

            {

                "Key": "aws:cloudformation:logical-id",

                "Value": "endpointSubnet"

            }

        ]

    }

Any Help?

1 Answer

0 votes
by (12.4k points)

It worked for me with both AWS CLI and boto3, 

providing code below:

import boto3

client = boto3.client('ec2')

subnets = client.describe_subnets()

for subnet in subnets['Subnets']:

    print(subnet['AvailabilityZone'], subnet['AvailabilityZoneId'])

and this the following output I got:

us-east-1b use1-az2

us-east-1e use1-az3

us-east-1d use1-az6

...

Maybe your AWS CLI or boto3 is of an older version or outdated. 

Do checkout AWS Certification to learn more about AWS.

Related questions

0 votes
1 answer
asked Sep 21, 2020 in AWS by Justin (7k points)
Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
asked Sep 21, 2020 in AWS by Justin (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...