How to get the latest Ubuntu AMI

1 minute read

Logo Terraform

Recently I needed to get the latest AMI for Ubuntu Trusty 14.04 Ubuntu with ENA support enabled to build an image using Packer so I did a research and found a way to do it using the AWS CLI. All those AMIs can be found listed on a page called ‘Ubuntu EC2 AMI Locator’. These approaches worked but then I wanted to avoid humans errors therefore I kept on doing more research and found a way to do it directly with Packer’s templates. Below I show both ways:

Using the AWS CLI

My first approach was to use the the AWS CLI as shown below:

aws ec2 describe-images \
--owners 099720109477 \
--filters Name=root-device-type,Values=ebs \
Name=architecture,Values=x86_64 \
Name=name,Values='*hvm-ssd/ubuntu-trusty-14.04*' \
Name=ena-support,Values=true \
--query 'sort_by(Images, &Name)[-1].[ImageId,CreationDate]' \
--output text --region us-east-1

ami-f0f8d695	2017-11-21T15:21:29.000Z

In this example, 099720109477 stands for Ubuntu’s owner ID.

Ubuntu Amazon EC2 AMI Locator

I also ran into the Amazon EC2 AMI Locator which can be a useful resource, specially if you dont have access to the AWS CLI.

Packer source ami filter:

With Packer you can use the source_ami_filter passing similar parameters like in the AWS CLI:

  "builders": [
      "type": "amazon-ebs",
      "region": "us-east-1",
      "instance_type": "c3.xlarge",
      "ena_support": true,
      "source_ami_filter": {
        "filters": {
        "virtualization-type": "hvm",
        "name": "ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*",
        "root-device-type": "ebs"
        "owners": ["099720109477"],
        "most_recent": true


Leave a Comment