Search code examples
amazon-web-servicesaws-cloudformationamazon-ecs

How to fix a drifted AWS CloudFormation stack?


How to fix a drifted AWS CloudFormation stack? I modified a BackendECS Service and it is now "drifted" but there's no information on how to resolve this? This is driving me insane? Zero information on how to resolve this?


Solution

  • Amazon AWS allows troubleshooting of a drifted stack via its "Drift Detection" feature.

    Drift detection can be accessed by navigating to CloudFormation > Select Stack > Actions > Detect Drift for current stack

    More on this here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/detect-drift-stack.html

    Using this diagnostic tool you can view exactly what is different in your AWS configuration as compared to the state that cloudformation expects.

    There are a few ways to potentially resolve this.

    1. If you did an automated update via an Infrastructure as code service, rollback your change

    2. If you manually updated the ECS Service, change the settings back to the expected state as shown in the drift detection. Once your system is back to the expected state your stack will behave normally

    3. Delete the current stack resource and re-create it - this is a dangerous way to resolve this as you will lose your update history and rollback states.

    ADDING theimowski's fourth alternative from the comments section:

    1. First remove deleted resources from template and update the stack,the bringing it back exactly as it was before in the template and updating the stack again. – theimowski Dec 29, 2021 at 16:38