1
votes

I have a CloudFormation template with that creates a Launch Configuration:

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   

When I try to update the stack I get the below error:

CloudFormation cannot update a stack when a custom-named resource requires replacing

I am running this script via TeamCity so it is not possible for the user to change the Launch Confoiguration's name each time. What can I do to get rid of this error?

2

2 Answers

4
votes

One solution can be to omit the LaunchConfigurationName since it is not mandatory.

Copied from the AWS::AutoScaling::LauncConfiguration documentation:

The name of the launch configuration. This name must be unique per Region per account. [...]

Update requires: Replacement

The problem you are facing is that you have made a change which requires the replacement of the launch configuration. Typically, CloudFormation creates a new resource (in case the existing resource cannot be updated), points any dependant resources to the new resource and then deletes the old resource. However, this operation fails if the resource uses a static name because then it conflicts with the unique name constraint mentioned in the docs.

0
votes

You can either:

  1. Do what @matsev recommended and not use names for resources that don't require it (probably the best option) - names will be generated based on stack name.
  2. Add a variable into your Resource name, such as a parameter which passes in commit-id or date or something along those lines. This will ideally make your Resource name unique.