Skip to content

Instantly share code, notes, and snippets.

@gservat
Created January 9, 2018 22:31
Show Gist options
  • Save gservat/75541be5ac76447b6321ae3285530841 to your computer and use it in GitHub Desktop.
Save gservat/75541be5ac76447b6321ae3285530841 to your computer and use it in GitHub Desktop.
Create a CSV with the available instance types in each AZ
#!/bin/bash
echo "Getting list of Availability Zones"
all_regions=$(aws ec2 describe-regions --output text --query 'Regions[*].[RegionName]' | sort)
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 <<< "$all_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-reserved-instances-offerings --filters "Name=availability-zone,Values=$az" --region $region)
instance_types=$(echo $raw | jq '.ReservedInstancesOfferings[] | .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