-
-
Save cbron/64ca7c002b3bd37ebd889cb720b7e276 to your computer and use it in GitHub Desktop.
Check a specific EC2 Instance Type in All Availability Zones
This file contains 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 | |
check_instance_type="m5.large" | |
product_description="Linux/UNIX" | |
echo > instance-types.csv | |
echo "Getting list of Availability Zones" | |
all_regions=$(aws ec2 describe-regions --region us-east-1 --output text --query 'Regions[*].[RegionName]' | sort) | |
all_az=() | |
while read -r region; do | |
echo "Checking region $region" | |
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 --instance-type $check_instance_type --region $region --availability-zone $az --no-include-marketplace --product-description $product_description) | |
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 | |
echo "See instance-types.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment