Created
May 25, 2018 15:43
-
-
Save evadne/41892f8fad7569c2b212d280e59aface to your computer and use it in GitHub Desktop.
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
#!/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