Skip to content

Instantly share code, notes, and snippets.

@loivis
Created September 28, 2017 13:33
Show Gist options
  • Save loivis/04c791ee37813af0fd863942713bbc8f to your computer and use it in GitHub Desktop.
Save loivis/04c791ee37813af0fd863942713bbc8f to your computer and use it in GitHub Desktop.
#!/bin/bash
# latest ubuntu 16.04 ami
aws ec2 describe-images --owners "099720109477" --filters Name="root-device-type",Values="ebs" \
Name=architecture,Values=x86_64 Name=name,Values='ubuntu/images/hvm-ssd/ubuntu-xenial-16.04*' \
--query 'sort_by(Images, &CreationDate)[-3:].[ImageId, CreationDate, Name]' --output=text
aws ec2 describe-images --owners "099720109477" --filters Name="root-device-type",Values="ebs" \
Name=architecture,Values=x86_64 Name=name,Values='ubuntu/images/hvm-ssd/ubuntu-xenial-16.04*' \
--query 'sort_by(Images, &CreationDate)[-1].ImageId' --output=text
# latest centos 7 ami
aws ec2 describe-images --filter Name='name',Values='CentOS Linux 7 x86_64 HVM EBS 1704*' Name='product-code',Values='aw0evgkw8e5c1q413zgy5pjce' \
--query 'Images[].[ImageId, CreationDate, Name]' --output text
aws ec2 describe-images --filter Name='name',Values='CentOS Linux 7 x86_64 HVM EBS 1704*' Name='product-code',Values='aw0evgkw8e5c1q413zgy5pjce' \
--query 'Images[].ImageId' --output text
# latest amazon ecs-optimized ami
aws ec2 describe-images --owners "amazon" --filter Name='name',Values='*amazon-ecs-optimized' \
--query 'sort_by(Images, &CreationDate)[-3:].[ImageId, CreationDate, Name]' --output text
aws ec2 describe-images --owners "amazon" --filter Name='name',Values='*amazon-ecs-optimized' \
--query 'sort_by(Images, &CreationDate)[-1].ImageId' --output text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment