Finding Ubuntu Images with the AWS SSM Parameter Store

Canonical is the publisher of official Ubuntu images on the Amazon cloud. Canonical is now able to publish information about the latest Ubuntu Images into AWS Systems Manager (SSM) parameter store.

These parameters can be used to determine the latest Ubuntu Amazon Machine Images (AMIs), support dates, and more. These parameters can be used directly in run-instances in EC2 and related services like CloudFormation. Additionally, these parameters are available through the GetParametersByPath, GetParameter, and GetParameters API actions for use in scripts and code.

Overview of Available Parameters

Canonical publishes parameters under the /aws/service/canonical space with the following hierarchies:

AMI ID

Parameter: .../ubuntu/PRODUCT/RELEASE/stable/current/ARCH/VIRT_TYPE/VOL_TYPE/ami-id

Where the fields are as follows:

  • PRODUCT: server or server-minimal
  • RELEASE: focal, 20.04, bionic, 18.04, xenial, or 16.04
  • ARCH: amd64 or arm64
  • VIRT_TYPE: pv or hvm
  • VOL_TYPE: ebs-gp2, ebs-io1, ebs-standard, or instance-store

Release Information

Each release has an end of standard maintenance and end of extended security maintenance date. These are obtained as ISO 8601 encoded date (YYYY-MM-DD) from the following paths:

  • .../ubuntu/server/RELEASE/meta/end-of-standard-maintenance-date
  • .../ubuntu/server/RELEASE/meta/end-of-extended-security-maintenance-date

Publisher ID

The official Canonical publisher ID used to publish images can be found from: .../meta/publisher-id

Examples

Latest AMI

The latest amd64 bionic AMI ID can be retrieved from the command line with:

aws ssm get-parameters --names \
        /aws/service/canonical/ubuntu/server/18.04/stable/current/amd64/hvm/ebs-gp2/ami-id \
    --query 'Parameters[0].[Value]' --output text

Run an instance with the latest amd64 focal AMI from the command line with:

aws ec2 run-instances \
    --image-id $(aws ssm get-parameters --names \
        /aws/service/canonical/ubuntu/server/focal/stable/current/amd64/hvm/ebs-gp2/ami-id \
    --query 'Parameters[0].[Value]' --output text) \
    --count 1 --instance-type m5.large

To help locating other AMIs from Canonical, use the Publisher ID:

aws ec2 describe-images --owner $(aws ssm get-parameters \
    --names /aws/service/canonical/meta/publisher-id \
    --query 'Parameters[0].[Value]' \
    --output text)

Historical Serial Lookup

If a user has an image serial they wish to confirm the AMI of then instead of using “current” the serial can be used:

aws ssm get-parameters --names \
        /aws/service/canonical/ubuntu/server/20.10/stable/20210222/amd64/hvm/ebs-gp2/ami-id \
    --query 'Parameters[0].[Value]' --output text

This change was introduced on serials dated 20210220 or later.

CloudFormation

Users can also reference these parameters in an AWS CloudFormation template:

Parameters:
    LatestAmiId:
        Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
        Default: '/aws/service/canonical/ubuntu/server/bionic/stable/current/amd64/hvm/ebs-gp2/ami-id’

Resources:
    Instance:
        Type: 'AWS::EC2::Instance'
        Properties:
            ImageId: !Ref LatestAmiId

More information about CloudFormation can be found at:
Integrating AWS CloudFormation with AWS Systems Manager Parameter Store

Terraform

Finally, users can also leverage AWS SSM in terraform templates:

data "aws_ssm_parameter" "ubuntu-focal" {
    name = "/aws/service/canonical/ubuntu/server/20.04/stable/current/amd64/hvm/ebs-gp2/ami-id"
}
5 Likes

What about if I want to take always the latest LTS?
Do you think that is possible to implement in RELEASE an alias for “lts”?

Thanks

Will this be available in AWS China? it doesn’t appear to work at the current moment.

Correct, publication to AWS China is a little different than other regions. We hope to have this available for AWS China at a future time.

Hi,

Is it possible to update SSM parameters for “Osaka” AWS region in public cloud and “us-gov-east-1” and “us-gov-west-1” AWS regions of GOV Cloud?

Application we developed is dependent on this SSM parameter, later are realized that it does return AMI Id for above mentioned regions.

It will be really helpful if this can be fixed as soon as possible.

Thanks.

Hi!

The recently opened up Osaka region (ap-northeast-3) will get SSM updates soon. We are waiting on our namespace to get added to the region before we can begin publishing updates to it.

As far as GovCloud SSM updates, this is something we would like to do as well, but not something that will get done soon. Besides the access restrictions that come along with GovCloud that complicate automation, we have some namespace work to do there as well.

Thanks!

Hi @pankajc123 ,

the SSM parameters for the latest available images are updated for “Osaka” (ap-northeast-3).
Please let us know if there are any problems.

Thanks!

Thank you so much for this.

Is it possible to update SSM parameter for "us-gov-east-1” and “us-gov-west-1” AWS regions of GOV Cloud also?

thanks.

This is on our TODO list, but not something we will work on in the near future.

Good write up. I think it would be also of great value to add how to use with --image-id resolve:ssm:/<parameter-name> as indicated in AWS docs here.

EDIT: For use e.g. with 22.04 this is what I ended up with:

aws ec2 run-instances \                                                                                           254 ↵
    --image-id resolve:ssm:/aws/service/canonical/ubuntu/server/22.04/stable/current/amd64/hvm/ebs-gp2/ami-id \
    --instance-type g4dn.2xlarge

@orfeas-k, thanks for reporting this. This documentation has been moved to https://documentation.ubuntu.com/aws/en/latest/aws-how-to/instances/find-ubuntu-images/ .

I have created https://github.com/canonical/ubuntu-cloud-docs/issues/201 representing your request.
Thanks again!

2 Likes

Thanks @orfeas-k for pointing this out and @aciba for creating the issue!

It is now included in the docs at https://documentation.ubuntu.com/aws/en/latest/aws-how-to/instances/find-ubuntu-images/#images-for-ec2-and-eks

2 Likes