-
-
Save ziwon/5733d99f70394f6f2d0801bd537bc810 to your computer and use it in GitHub Desktop.
Get all EC2 Instance Types in All Availability Zones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
region="ap-northeast-2" | |
all_az=() | |
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" | |
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 --location-type availability-zone --filters Name=location,Values=$az --region $region) | |
instance_types=$(echo $raw | jq '.InstanceTypeOfferings[] | .InstanceType' | sort -u | sed -e 's/"//g' ) | |
while read -r instance_type; do | |
echo "$region;$az;$instance_type" >> instance-types.csv | |
done <<< "$instance_types" | |
counter=$((counter+1)) | |
done | |
sed -i '' '1s/^/REGION;AZ;TYPE\n/' instance-types.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment