Skip to content

Instantly share code, notes, and snippets.

@evadne
Created May 25, 2018 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evadne/41892f8fad7569c2b212d280e59aface to your computer and use it in GitHub Desktop.
Save evadne/41892f8fad7569c2b212d280e59aface to your computer and use it in GitHub Desktop.
#!/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