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
orserver-minimal
- RELEASE:
focal
,20.04
,bionic
,18.04
,xenial
, or16.04
- ARCH:
amd64
orarm64
- VIRT_TYPE:
pv
orhvm
- VOL_TYPE:
ebs-gp2
,ebs-io1
,ebs-standard
, orinstance-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"
}