0

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?

StarCub
  • 4,141
  • 7
  • 41
  • 58
  • Is your question answered in https://stackoverflow.com/questions/58661858/aws-how-to-make-asg-always-use-the-latest-ami? – LRutten Sep 03 '21 at 17:05
  • @LRutten Not really. Now I know Launch Templates are immutable so sounds like I need to create a new Launch Template version for every AMI build, and the make the ASG to use that latest version. How can I achieve this? – StarCub Sep 04 '21 at 09:54
  • It's quite a tricky thing to do this with cloudformation, since CFN only updates infra when you run an `update-stack`. – LRutten Sep 04 '21 at 09:57

1 Answers1

0

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