Latest Amazon Linux AMI

2018-08-24 Nerd Software sergio

Again, found on the internet (but with some old code that was not getting the latest images), so again as the case of the latest CentOs ami post, as public memory

Assuming:

  • You want an HVM, EBS backed, x86_64 image of the latest version of Amazon Linux
  • You have configured the desired region and credentials for the AWS SDK
  • Owned by Amazon, of course.
# for the whole entry
aws ec2 describe-images                          \
  --owners amazon                                \
  --filters                                      \
    'Name=name,Values=amzn-ami-hvm-*-x86_64-gp2' \
    'Name=state,Values=available'                \
  | jq -r '.Images | sort_by(.CreationDate) | last(.[])'

# or to get only the image id
aws ec2 describe-images                          \
  --owners amazon                                \
  --filters                                      \
    'Name=name,Values=amzn-ami-hvm-*-x86_64-gp2' \
    'Name=state,Values=available'                \
  | jq -r '.Images | sort_by(.CreationDate) | last(.[]).ImageId'