Launch Template reference latest AMI built by codepipeline

460 views Asked by At

I have codepipeline that creates an AMI and I have created separate Cloudformation stack to create Launch template that uses the AMI. Currently the Launch Template Cloudformation has the AMI imageID hard-coded like this

LaunchTemplate:
    Type: AWS::EC2::LaunchTemplate
    Properties:
      LaunchTemplateData:
        ImageId: ami-xxxxxxxxxxxxxxx

What's the best way to update LaunchTemplate to always use the latest imageId built by codepipe line?

1

There are 1 answers

0
dparnovskiy On

Use

Parameters:
  Amiid:
    Type: AWS::SSM::Parameter::Value<String>
    Default: /aws/...<ssm parameter name for your AMI family>

This way CFN will fetch the latest AMI ID from SSM

Then use this parameter in

ImageId: !Ref Amiid