Created
September 7, 2018 12:35
-
-
Save daniyel/1a132a25f9373d8a0722765359d13e48 to your computer and use it in GitHub Desktop.
Get list of Ubuntu 16.04 LTS latest AMIs for AWS CloudFormation
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/sh | |
remove_last_comma() { sed ' | |
$x;$G;/\(.*\),/!H;//!{$!d | |
}; $!x;$s//\1/;s/^\n//' | |
} | |
response=$(curl -s "https://cloud-images.ubuntu.com/locator/ec2/releasesTable" | remove_last_comma) | |
regions=$(echo $response | jq -c '.aaData[] | select(contains(["16.04", "hvm:ebs"])) | .[0]' | sed 's/"//g') | |
images=$(echo $response | jq -c '.aaData[] | select(contains(["16.04", "hvm:ebs"])) | .[6]' | grep -o '>ami-[a-z0-9]\+' | sed 's/>//g') | |
regionsarr=(${regions//$'\n'/ }) | |
imagesarr=(${images//$'\n'/ }) | |
counter=0; | |
for region in "${regionsarr[@]}" | |
do | |
echo "$region:" | |
echo " US1604HVM: ${imagesarr[$counter]}" | |
counter=$((counter+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment