Skip to content

Instantly share code, notes, and snippets.

@chales
Forked from vancluever/amifind.sh
Created March 7, 2018 06:33
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 chales/bad3f854fa18a40543d902bc09b6f2b7 to your computer and use it in GitHub Desktop.
Save chales/bad3f854fa18a40543d902bc09b6f2b7 to your computer and use it in GitHub Desktop.
Find the most recent Ubuntu AMI using aws-cli (or any other AMI for that matter)
#!/bin/sh
# Use AWS CLI to get the most recent version of an AMI that
# matches certain criteria. Has obvious uses. Made possible via
# --query, --output text, and the fact that RFC3339 datetime
# fields are easily sortable.
export AWS_DEFAULT_REGION=us-east-1
aws ec2 describe-images \
--filters Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64* \
--query 'Images[*].[ImageId,CreationDate]' --output text \
| sort -k2 -r \
| head -n1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment