Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
Forked from antimius/find_latest_ami.sh
Last active October 13, 2017 22:31
Show Gist options
  • Save drmikecrowe/e4760beddcc26b30285db48f4e0f386a to your computer and use it in GitHub Desktop.
Save drmikecrowe/e4760beddcc26b30285db48f4e0f386a to your computer and use it in GitHub Desktop.
Script to find and print the latest stable, Ubuntu version
#!/bin/bash
# prints latest, stable, HVM, EBS GP2 backed AMIs for major OSs
UBUNTU=099720109477
REGIONS="us-east-1 us-east-2 us-west-1 us-west-2"
for REGION in $REGIONS; do
echo -n "$REGION: "
aws ec2 describe-images --region=$REGION --owners $UBUNTU --filters 'Name=name,Values=*hvm-ssd*16.04*' --query 'Images[*].[ImageId,CreationDate,Name]' --output text | sort -k2 -r | head -n 1
done
@drmikecrowe
Copy link
Author

output:

us-east-1: ami-bcdc16c6 2017-10-13T19:36:50.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
us-east-2: ami-49426e2c 2017-10-13T19:37:47.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
us-west-1: ami-1b17257b 2017-10-13T19:37:35.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011
us-west-2: ami-19e92861 2017-10-13T19:37:31.000Z        ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20171011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment