Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
export AWS_PROFILE=<snip>
ImageDescription="Amazon Linux AMI 2017.09.1.20180115"
RegionNames=$(aws ec2 describe-regions --region eu-west-1 --query 'Regions[*].[RegionName]' --output text)
function getImages () {
region=$1
filters="[
{\"Name\": \"owner-alias\", \"Values\": [\"amazon\"]},
{\"Name\": \"image-type\", \"Values\": [\"machine\"]},
{\"Name\": \"description\", \"Values\": [\"$ImageDescription*\"]}
]"
images=$(aws ec2 describe-images --region $region --cli-input-json "{\"Filters\": $filters}")
output=$(echo $images | jq -c ".Images | \
map({ \
(.Description | \
sub(\"^$ImageDescription[[:blank:]]*\"; \"\") | \
sub(\"^x86_64\"; \"\") | \
gsub(\"[^0-9A-Za-z]\"; \"\")): \
.ImageId \
}) | \
add | \
{\"$region\": .}")
echo $output
}
export ImageDescription
export -f getImages
RegionToImage=$(parallel getImages ::: $RegionNames)
echo $(echo $RegionToImage | jq -rsc add)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.