I'm trying to get the availability zone the instance type available in was. let's say I know the Region: us-west-2 and I also know which instance type I want: c5n.large.
is there a way to get the Availability Zones if I know the Region and the instance type? I'm looking for a way to do it with JS or Ruby code, and without authication .
what I found so far is running a command inside the instance but this is not helping me because I don't want to run the instance, I want the info before I run it.
az=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone)
echo ${az}
I want to provide:
AWS region (i.e us-west-2)
EC2 instance type (i.e c5n.large)
and get back:
list of all availability zones (i.e us-west-2b, us-west-2c), in which that instance type is available
thank you!
CodePudding user response:
You can use describe-instance-type-offerings (or equivalent in SDK) and filter it for your instance type and region. Eg.:
aws ec2 describe-instance-type-offerings --location-type "availability-zone" --region us-east-1 --query "InstanceTypeOfferings[?InstanceType=='c5n.large'].[InstanceType,Location]" --output text
which will return:
c5n.large us-east-1c
c5n.large us-east-1f
c5n.large us-east-1a
c5n.large us-east-1b
c5n.large us-east-1d