Skip to content

Instantly share code, notes, and snippets.

@Zate
Created February 4, 2018 18:47
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 Zate/77b41a47e32eca0be8013413e4d80d09 to your computer and use it in GitHub Desktop.
Save Zate/77b41a47e32eca0be8013413e4d80d09 to your computer and use it in GitHub Desktop.
Script to grab latest Amazon Linux AMI's to include in cloudformation templates.
!/bin/bash
# runs through each region and grabs the latest Amazon Linux AMI to be used for standard EC2 Instances.
# use this to make sure the right AMI ID's are in the cloudformation templates.
tabs 4
echo -e "\tAWSRegionToAMI:"
for region in `aws ec2 describe-regions --output text | cut -f3`
do
ami=`aws ec2 describe-images --region $region --owners amazon --filters 'Name=name,Values=amzn-ami-hvm*x86_64-gp2' 'Name=state,Values=available' | jq -r '.Images | sort_by(.CreationDate) | last(.[]) | .ImageId'`
echo -e "\t\t$region:\n\t\t\tAMIID: $ami"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment