cloudformation 堆栈更新和启动模板版本/自动缩放组的问题

Tre*_*ths 6 aws-cloudformation

我在 cloudformation 中有一个堆栈(ECS 集群、应用 LB、自动缩放组、启动模板等),一切正常,我们已经在生产和预生产环境中使用了一段时间。

最近在尝试推送堆栈更新时出现了一个问题。我对 AWS::EC2::LaunchTemplate 中的 UserData 进行了一些更改。如果我从这个模板启动一个新堆栈,它会很好用。
但是:如果我进行更改集并应用堆栈更新 cloudformation 会创建一个新的启动模板版本 - 但是 - 自动缩放组仍然引用旧版本。查看 AWS::AutoScaling::AutoScalingGroup LaunchTemplateSpecification 的 AWS 文档

我看到:“AWS CloudFormation 不支持为模板版本号指定 $Latest 或 $Default。”

任何人都在创建需要在其他地方引用的新版本资源的堆栈更新中争论不休?我觉得我错过了一些明显的东西。

Tre*_*ths 7

是的,我很笨:使用 Fn::GetAtt 好吧,取笑我使用 json 而不是 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"}]
                                   }
        }
      },

...
Run Code Online (Sandbox Code Playgroud)