Skip to content

Instantly share code, notes, and snippets.

@belminf
Last active August 6, 2021 23:27
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save belminf/6d55c21e3d0499eaca09 to your computer and use it in GitHub Desktop.
AWS CLI command to find latest RHEL and Ubuntu images using JMESPath
# Both are limited to HVM-based 64-bit AMIs backed by EBS
# Red Hat's latest GA images
alias ami_rhel="aws ec2 describe-images \
--filters \
'Name=root-device-type,Values=ebs' \
'Name=architecture,Values=x86_64' \
'Name=virtualization-type,Values=hvm' \
'Name=name,Values=*GA*' \
--owners 309956199498 \
--output table \
--query 'reverse(Images.sort_by([], &CreationDate))[].[ImageId, Name]'"
# Canonical's 20 latest non-beta/testing images
alias ami_ubuntu="aws ec2 describe-images \
--filters \
'Name=root-device-type,Values=ebs' \
'Name=architecture,Values=x86_64' \
'Name=virtualization-type,Values=hvm' \
--owners 099720109477 \
--output table \
--query 'reverse(Images.sort_by([], &CreationDate))[?contains(Name,\`test\`)==\`false\`]|[?contains(Name,\`beta\`)==\`false\`]|[?contains(Name,\`Snappy\`)==\`false\`]|[0:20].[ImageId, Name]'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment