0

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!

DevFromI
  • 191
  • 1
  • 20
  • Sadly your question is not clear. What exactly do you want to do? If if c5n.large is in all availability zones? – Marcin Aug 15 '22 at 10:44
  • if c5n.large in all availability zones, so I should get the name of all of the availability zones related to the region. but If i choose c5n.small and its in 2/3 availability zones, i should get only this 2 on the output. @Marcin – DevFromI Aug 15 '22 at 10:46
  • Ok. So what did you try? Did you write any JS or Ruby code, or expect someone to write it from scratch? – Marcin Aug 15 '22 at 10:47
  • @Marcin i didnt find anything to start with, in order to get this info. – DevFromI Aug 15 '22 at 10:48
  • What info? Its not clear what do you want to do. Are these instance yours? You want to query your own instance that is running in your account? Or you just want to know what instance types are available in AWS in which AZ? – Marcin Aug 15 '22 at 10:49
  • I will explain again: i want to get availability zones (names) of a instance type. by given the region + instance type. so lets say my program get : US-WEST2 as region and instance type: c5n.large c5n.large works only in us-west-2b,us-west-2a. the output will be: ["us-west-2b","us-west-2a"] @Marcin – DevFromI Aug 15 '22 at 10:52

1 Answers1

3

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
Marcin
  • 215,873
  • 14
  • 235
  • 294