AWS EC2 launching latest ubuntu Image in Cloud Formation Template

Viewed 1392

I have CFT that have in the parameter section:

  LatestAmiId:
    Type:  'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'

in the Resource section for EC2:

EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      InstanceType: !Ref 'InstanceType'
      SecurityGroups: [!Ref 'InstanceSecurityGroup']
      KeyName: !Ref 'KeyName'
      ImageId: !Ref 'LatestAmiId'

Such setup gives me always the latest AMI image to Amazon Linux distribution - I want to start using Ubuntu 18.x -

What I should put in Default Section (or as Parameter)?

1 Answers

Recently Canonical started storing the latest Ubuntu AMI IDs in public SSM parameters, much like Amazon does for Amazon Linux:

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

Resources:
  UbuntuInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: !Ref LatestUbuntuFocalAMI

Source: https://discourse.ubuntu.com/t/finding-ubuntu-images-with-the-aws-ssm-parameter-store/15507

Related