Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeremy-donson/dd96148b07207ebd3b3a8042165cba5d to your computer and use it in GitHub Desktop.
Save jeremy-donson/dd96148b07207ebd3b3a8042165cba5d to your computer and use it in GitHub Desktop.
BASH SCRIPT: Queries AWS for the *latest* AMI images per global region, writes them to a file, and then reads that file back to us.
#!/bin/bash
# This queries AWS for the *latest* AMI images per global region, writes them to a file, and then reads that file back to us.
for REGION in $(aws ec2 describe-regions --query "Regions[].RegionName" --output json | jq -r '.[]');
do
echo "$region = $(aws ec2 describe-images --owners amazon \
--filters 'Name=name,Values=amzn-ami-hvm-????.??.?.x86_64-gp2'\
--query 'sort_by(Images, &CreationDate) | [-1].ImageId' --region $REGION)";
done > ~/aws-latest-images-per-region.txt
cat ~/aws-latest-images-per-region.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment