Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with cloudformation stack update and launch template version / autoscaling group

I have a stack in cloudformation (ECS cluster, App LB, Autoscaling Group, launch templates, etc etc.) It all works fine and we have been using this in production and pre production environments for a while.

A problem recently arose while trying to push a stack update. I made some changes to UserData in the AWS::EC2::LaunchTemplate. If i launch a new stack from this template it works great.
BUT: If i make a change set and apply a stack update cloudformation creates a NEW launch template version -however- the autoscaling group still references the OLD version. Looking at the AWS docs for AWS::AutoScaling::AutoScalingGroup LaunchTemplateSpecification

I see: "AWS CloudFormation does not support specifying $Latest, or $Default for the template version number."

Anyone wrangled w/ stack updates creating new versions of resources that need to be referenced elsewhere? I feel like i am missing something obvious.

like image 607
Trevor Griffiths Avatar asked Jul 04 '19 16:07

Trevor Griffiths


1 Answers

yay, i'm dumb: use Fn::GetAtt ok, make fun of me for using json not yaml

...

"ECSAutoScalingGroup": {
            "Type": "AWS::AutoScaling::AutoScalingGroup",
            "Properties": {
                "VPCZoneIdentifier": {"Ref" : "Subnets"},
                "MinSize": "1",
                "MaxSize": "10",
                "DesiredCapacity": { "Ref": "DesiredInstanceCount" },
        "MixedInstancesPolicy": {
             "InstancesDistribution" :
                    {
                     "OnDemandBaseCapacity" : "0",
                     "OnDemandPercentageAboveBaseCapacity" : { "Ref" : "PercentOnDemand"}
                    },
             "LaunchTemplate" : {
               "LaunchTemplateSpecification" : {
                      "LaunchTemplateId" : {"Ref" : "ECSLaunchTemplate"},
                      "Version" : { "Fn::GetAtt" : [ "ECSLaunchTemplate", "LatestVersionNumber" ] }
                       },
                    "Overrides" : [ {"InstanceType": "m5.xlarge"},{"InstanceType": "t3.xlarge"},{"InstanceType": "m4.xlarge" },{"InstanceType": "r4.xlarge"},{"InstanceType": "c4.xlarge"}]
                                   }
        }
      },

...
like image 175
Trevor Griffiths Avatar answered Sep 30 '22 07:09

Trevor Griffiths