Skip to content

Instantly share code, notes, and snippets.

@serithemage
Forked from trestletech/instance-types.sh
Last active June 2, 2023 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save serithemage/35fd0253d3ca4b7a73a00cc6dc99fea4 to your computer and use it in GitHub Desktop.
Save serithemage/35fd0253d3ca4b7a73a00cc6dc99fea4 to your computer and use it in GitHub Desktop.
Get all EC2 Instance Types in All Availability Zones
#!/bin/bash
# Getting list of Availability Zones from target region
# all
#target_regions=$(aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' | sort)
# default region
target_regions=$(aws configure get region)
echo "Target regions:"
echo $target_regions
all_az=()
while read -r region; do
az_per_region=$(aws ec2 describe-availability-zones --region $region --query 'AvailabilityZones[*].[ZoneName]' --output text | sort)
while read -r az; do
all_az+=($az)
done <<< "$az_per_region"
done <<< "$target_regions"
counter=1
num_az=${#all_az[@]}
for az in "${all_az[@]}"
do
echo "Checking Availability Zone $az ($counter/$num_az)"
region=$(echo $az | rev | cut -c 2- | rev)
raw=$(aws ec2 describe-instance-type-offerings --filters "Name=location,Values=$az" --location-type availability-zone --region $region)
instance_types=$(echo $raw | jq '.InstanceTypeOfferings[] | .InstanceType' | sort -u)
while read -r instance_type; do
echo "$region;$az;$instance_type" >> instance-types.csv
done <<< "$instance_types"
counter=$((counter+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment