Question

Difficulty: MediumAWS CloudFormation

A company is updating an infrastructure stack deployed via AWS CloudFormation. The template contains an Amazon DynamoDB table that needs to be modified. The planned modification requires CloudFormation to replace the DynamoDB resource. The developer wants to ensure that the database's existing data is preserved and the resource is not deleted during this replacement, as well as if the stack is deleted in the future. Which configuration should the developer apply to the DynamoDB resource in the template?

  1. A
    Specify only DeletionPolicy with the Retain value, as this attribute automatically applies to both resource replacement updates and stack deletions.
  2. B
    Apply an UpdatePolicy attribute with the AutoSnapshot property set to true, and set the DeletionPolicy to Retain.
  3. Specify both DeletionPolicy and UpdateReplacePolicy with the Retain value in the resource attributes.Answer
  4. D
    Enable stack termination protection and configure a Systems Manager Parameter Store parameter to track the resource state.

Answer

Specify both DeletionPolicy and UpdateReplacePolicy with the Retain value in the resource attributes.
To protect a resource from being deleted during both stack updates (when a change requires resource replacement) and stack deletion, you must specify both the DeletionPolicy and UpdateReplacePolicy attributes and set their values to Retain (or Snapshot if supported). Setting DeletionPolicy only protects the resource when the stack is deleted or the resource is removed from the template, but does not prevent deletion of the old resource during a replacement update. UpdateReplacePolicy specifically controls the behavior when a resource is replaced during a stack update.

Step-by-Step Solution

1
Analyze the resource modification requirements in the AWS CloudFormation template.
Identify that the modification to the Amazon DynamoDB table will trigger a resource replacement during a stack update.
Certain property updates (such as changing a partition key) cannot be applied to an existing DynamoDB table and require CloudFormation to create a new table and delete the old one.
2
Evaluate resource protection attributes for both stack updates and stack deletion.
Determine that DeletionPolicy only protects resources when the stack is deleted or when the resource is removed from the template, while UpdateReplacePolicy protects resources when they are replaced during updates.
Using only DeletionPolicy would result in the deletion of the old DynamoDB table when it is replaced during a stack update.
3
Apply both attributes to the resource definition in the template.
Configure DeletionPolicy: Retain and UpdateReplacePolicy: Retain on the DynamoDB table resource.
This combination ensures the table is preserved (retained in the AWS account) during both resource replacement updates and stack deletion.

Key Concept

Managing resource lifecycle and preserving data during AWS CloudFormation stack updates and deletions using DeletionPolicy and UpdateReplacePolicy.
Rate this question