Select Language:
When updating a CloudFormation stack, whether a resource is replaced depends on specific settings related to how the change is evaluated. Specifically, it hinges on the “RequiresRecreation” property and whether the change is considered static or dynamic during evaluation.
If a modification requests a resource replacement and “RequiresRecreation” is set to “Always” with a “Static” evaluation, CloudFormation will definitely replace the resource. However, if “RequiresRecreation” is still “Always” but the evaluation is “Dynamic,” the process is less straightforward, and the replacement may only happen conditionally.
For example, when changing permissions for an AWS Lambda function, if your update shows a replacement because you’ve switched from a fixed account ID to a function that pulls the account ID dynamically (using something like “Fn::AccountIdFromAlias”), whether CloudFormation actually performs the replacement depends on how the account ID is evaluated at runtime. If the dynamic function resolves to the same account ID as before, CloudFormation might detect that no real change has occurred and skip the replacement. Conversely, if it treats the change as static and requires recreation regardless of the final value, it will replace the resource even if the account ID remains the same after resolution.
The core difference lies in CloudFormation’s evaluation method — whether it looks at the change as a static modification (based on the template alone) or as a dynamic one (based on the actual value at runtime). Essentially, the resource will only be replaced if the evaluated value differs in a way that necessitates recreating the resource.
To understand how your particular update will behave, you need to consider if the change involves a static or dynamic evaluation and whether the resolved value at runtime will differ from the previous one. This approach helps you anticipate whether an update will lead to a resource replacement or not.





