Is it possible to re-create AWS resources using CloudFormation?


Lets say an AWS stack was created using CloudFormation.
Now one of those resources was modified outside CloudFormation.

1) Is it possible to have CloudFormation specifically create those resources? Based on my understanding, we can’t do that because CloudFormation does not identify a difference, and so does not create the modified resources. Is my observation correct?

2) Also, what options do I have to revert a stack to its original state, if modified outside CloudFormation?


First, beware that modifying CloudFormation-created resources outside of CloudFormation is explicitly discouraged, according to AWS CloudFormation Best Practices:

Manage All Stack Resources Through AWS CloudFormation

After you launch a stack, use the AWS CloudFormation console, API, or AWS CLI to update resources in your stack. Do not make changes to stack resources outside of AWS CloudFormation. Doing so can create a mismatch between your stack’s template and the current state of your stack resources, which can cause errors if you update or delete the stack.

However, if you’ve modified a CloudFormation-managed resource accidentally and need to recover, you may have some limited options beyond simply deleting and re-creating the stack altogether (which may not be an acceptable option):

  1. It is not possible for CloudFormation to automatically update its internal state based on the current state of an externally-modified resource.

    However, depending on the exact resource type, in some cases you can manually update CloudFormation afterwards by applying a stack update that matches the current state of the resource.

  2. Similarly, it is not possible for CloudFormation to automatically revert an externally-modified resource back to its original unmodified CloudFormation state.

    However, depending on the exact resource type, in some cases you can either:

    • Revert a resource by manually updating the resource back to its original state;
    • Update the resource by applying a stack update, bringing both the CloudFormation stack and the managed resource to an altogether new state that will once again be in sync.

Leave a Reply