Found a way to get the (complete?) list programmatically, although it took me a few commands. This should work with bash
or zsh
, should be easy to adapt elsewhere.
It's unfortunately quite slow; parallelizing the call to aws pricing
would help. Finding the magic product that has exactly one SKU in every region would be even better, but I have no idea what that SKU might be.
[Also, I'm on a Mac, so (1) these are probably the BSD-ish versions of things like sed
; and (2) I'm stuck on Bash3, so I'm being pretty basic in my usage.]
# Get list of regions codes.
all_regions=( $( aws pricing get-attribute-values \
--region us-east-1 \
--service-code AmazonEC2 \
--attribute-name regionCode \
--output text \
--query AttributeValues ) )
# Fetch one product from each, grab out the human-friendly location.
# This is a bit slow (took about 90s here).
typeset -a all_regions_and_names
all_regions_and_names=()
for region in "${all_regions[@]}"
do
region_and_name=$( \
aws pricing get-products \
--region us-east-1 \
--service-code AmazonEC2 \
--filters "Type=TERM_MATCH,Field=regionCode,Value=$region" \
--max-items 1 \
| jq -rc '.PriceList[]' \
| jq -r '.product.attributes | "\(.regionCode)=\(.location)"'
)
all_regions_and_names+=( $region_and_name )
done
Once you have that (array) variable, it's easy to turn it into a text table:
( echo "region=name"
echo "----------------------=------------------------------"
IFS=$'\n'
echo "${all_regions_and_names[*]}" | sort | uniq
) \
| column -s = -t
Sample output:
region name
---------------------- ------------------------------
af-south-1-los-1 Nigeria (Lagos)
af-south-1 Africa (Cape Town)
ap-east-1 Asia Pacific (Hong Kong)
...
Or into JSON:
echo '{'
(
IFS=$'\n'
echo "${all_regions_and_names[*]}" | sort | uniq
) \
| sed -E -e 's/^(.*)=(.*)$/ "\1":="\2",/' \
-e '$,$ s/,$//' \
| column -t -s =
echo '}'
Sample output:
{
"af-south-1-los-1": "Nigeria (Lagos)",
"af-south-1": "Africa (Cape Town)",
"ap-east-1": "Asia Pacific (Hong Kong)",
...
}
Note that the pricing
API is only available in us-east-1
and ap-south-1
hence the --region
option above (which only controls the AWS API endpoint used; it does not narrow the query itself at all.)
(It could be done in a single command if someone knows of a single product that is available in every region and local zone. Alternately, you could ask it to list everything available under a particular serviceCode
, but that gets huge fast -- hence my simple --max-items 1
workaround above.)
Even this might not be complete, if there are zones which don't offer EC2 instances at all. Hopefully you're ultimately trying to answer the question "where can I get an X and what do I have to call the region I'm trying to get one", so you can just adjust the serviceCode
.
Hat tip to How to get ec2 instance details with price details using aws cli which got me started down this path.