Created
February 4, 2018 18:47
-
-
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.
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/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