An engineer manages a stateful "Amazon RDS" database inside an "AWS CloudFormation" stack that also defines networking and compute. The business requires that if the entire stack is ever deleted, the database must survive so a final snapshot and the data are not lost, while every other resource should be removed normally. The engineer wants this behaviour expressed in the template itself rather than relying on a manual pre-delete step. Which configuration BEST achieves this?
- AEnable termination protection on the stack so that an accidental stack deletion is blocked and the database along with all other resources is preserved.
- BAdd a stack policy that denies the "Delete" action on the database logical ID so the resource cannot be removed when the stack is deleted.
- CSet an "UpdateReplacePolicy" of "Retain" on the database so the resource is preserved whenever the stack is deleted by an operator.
- DSet a "DeletionPolicy" of "Retain" on the database resource so it is kept when the stack is deleted while the remaining resources are removed normally. Correct
Why A is wrong: Termination protection blocks deletion of the whole stack rather than preserving one resource on an intended delete, and it keeps everything, not just the database, so it does not match the selective-retention requirement.
Why B is wrong: Stack policies govern updates to a running stack, not stack deletion, so a deny on Delete in a stack policy does not protect a resource when the whole stack is being torn down.
Why C is wrong: UpdateReplacePolicy controls what happens to the old resource when an update forces a replacement, not what happens on stack deletion, so it does not preserve the database when the stack is deleted.
Why D is correct: A DeletionPolicy of Retain on a single logical resource tells CloudFormation to leave that resource in place when the stack is deleted while still removing resources that lack the policy, which is precisely the selective behaviour required.