首页 > 解决方案 > 当自定义命名资源需要替换时,CloudFormation 无法更新堆栈

问题描述

我有一个 CloudFormation 模板,它创建了一个启动配置:

Resources:
# Launch Configuration for the instances in the Atoscaling Group
  LaunchConfiguration:
    Type: AWS::AutoScaling::LaunchConfiguration
    Properties:
      AssociatePublicIpAddress: false
      ImageId: !Ref EC2AMI
      InstanceType: !Ref EC2InstanceType
      KeyName: !Ref EC2Key
      IamInstanceProfile: !ImportValue EC2RoleInstanceProfileARN
      LaunchConfigurationName: jxt-private-asg-launch-config
      SecurityGroups:
        - !ImportValue PrivateSecurityGroupId   

当我尝试更新堆栈时,出现以下错误:

当自定义命名资源需要替换时,CloudFormation 无法更新堆栈

我通过 TeamCity 运行此脚本,因此用户不可能每次都更改启动配置的名称。我能做些什么来摆脱这个错误?

标签: amazon-web-servicesamazon-cloudformation

解决方案


一种解决方案可以是省略,LaunchConfigurationName因为它不是强制性的。

复制自AWS::AutoScaling::LauncConfiguration 文档

启动配置的名称。此名称在每个区域的每个账户中必须是唯一的。[...]

更新要求:更换

您面临的问题是您进行了更改,需要更换启动配置。通常,CloudFormation 会创建一个新资源(以防现有资源无法更新),将任何依赖资源指向新资源,然后删除旧资源。但是,如果资源使用静态名称,则此操作将失败,因为它与文档中提到的唯一名称约束冲突。


推荐阅读