DOP-C02 Practice Question 53: CFN Deletion Replace Policy
AWS Certified DevOps Engineer – Professional (DOP-C02) · Test 6 · question 3 of 10
A CloudFormation template provisions a production RDS DB instance. Operators need two independent guarantees for that resource. First, if a future stack update ever forces CloudFormation to replace the DB instance, the old instance must not be deleted; it should remain intact so it can still be inspected. Second, if the stack itself is ever deleted, CloudFormation must take a final DB snapshot before removing the instance rather than deleting it outright.
Which combination of resource attributes on the DB instance satisfies both requirements?
Show answer and explanation
Answer:
DeletionPolicy controls what CloudFormation does to a resource when the resource is removed because the stack is deleted; Snapshot is supported for resources such as RDS DB instances, EBS volumes, ElastiCache clusters and Redshift clusters, and it takes a final snapshot before deleting the underlying resource. UpdateReplacePolicy controls a different event: what happens to the old resource when a stack update forces CloudFormation to replace it with a new one; Retain keeps the old resource around instead of deleting it. Setting DeletionPolicy: Snapshot together with UpdateReplacePolicy: Retain covers both requirements independently.
Option B swaps the two policies: DeletionPolicy: Retain would leave the instance running forever on stack deletion with no snapshot taken, and UpdateReplacePolicy: Snapshot is not a valid combination for satisfying the stated requirement of keeping the old instance intact.
Option C is wrong because UpdateReplacePolicy defaults to Delete, not Retain; CloudFormation deletes a replaced resource unless UpdateReplacePolicy is explicitly set, so it must be specified.
Option D only addresses accidental deletion of the whole stack through the console or CLI; termination protection does not create a snapshot. For a standalone DB instance the default DeletionPolicy is already Snapshot, but nothing sets UpdateReplacePolicy, which defaults to Delete, so an update that forces replacement still deletes the old instance without a snapshot.
Reference: DeletionPolicy attribute