Courseiva
Configuration Management and IaCmediumMultiple ChoiceObjective-mapped

DOP-C02 Configuration Management and IaC Practice Question

A company uses AWS CloudFormation to manage its infrastructure. The DevOps team wants to ensure that critical resources, such as an RDS database, are not accidentally deleted when a stack is updated or deleted. Which CloudFormation feature should be used to prevent this?

⚠ Common exam trap

Test-takers frequently confuse termination protection (an EC2-specific feature) with CloudFormation's DeletionPolicy, or mistakenly think a stack policy can prevent deletion during a full stack deletion, when it only restricts update operations.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

DeletionPolicy attribute with Retain

The DeletionPolicy attribute with the Retain value is the correct choice because it explicitly instructs CloudFormation to preserve the physical resource (e.g., an RDS database) when its corresponding logical resource is deleted from the stack template during an update or when the entire stack is deleted. This prevents accidental deletion of critical stateful resources by ensuring the resource remains in the AWS account even after the stack operation completes.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • DeletionPolicy attribute with Retain

    Why this is correct

    DeletionPolicy: Retain on a resource instructs AWS CloudFormation to preserve that physical resource when the stack is deleted. Without it, DeleteStack removes every resource in the template; with Retain, the resource is simply left in place and becomes orphaned, allowing you to keep critical data such as databases or S3 buckets. This is the standard way to prevent accidental data loss during stack deletion.

  • Stack policy

    Why it's wrong here

    A stack policy is a JSON document that controls which resources can be updated by a stack update operation, using Allow or Deny statements. It is evaluated only when UpdateStack is called, and it has no bearing on DeleteStack or on resource deletion. Even a policy that denies all updates will not stop CloudFormation from deleting resources when the stack is removed, so it cannot serve as deletion protection.

  • Termination protection

    Why it's wrong here

    Termination protection is an Amazon EC2 instance-level setting designed to prevent accidental instance termination via the console or API; it is not a CloudFormation stack or resource attribute. If an EC2 instance in a stack has termination protection enabled, a stack deletion may fail on that resource rather than cleanly preserving it, and the setting does nothing for non-EC2 resources like RDS or S3. Consequently, it is not a general mechanism for preserving stack resources on deletion.

  • DependsOn attribute

    Why it's wrong here

    DependsOn is a CloudFormation attribute that only specifies the order in which resources are created, ensuring a dependent resource is created after the resources it relies on. Deletion order is the reverse of creation order, but DependsOn provides no instruction to skip or retain any resource during stack deletion. It is purely a dependency-ordering construct and cannot prevent a resource from being destroyed when the stack is deleted.

About these practice questions

One of 251 original DOP-C02 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

2 more ways this is tested on DOP-C02

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A company uses AWS CloudFormation to manage infrastructure. They have a stack that creates an Amazon RDS DB instance and an EC2 instance that connects to it. The DB instance has a deletion policy of 'Retain'. The stack fails to delete because the DB instance is retained and still exists. Which TWO actions would allow the stack to be deleted successfully? (Select TWO.)

medium
  • A.Use the AWS CLI to force delete the stack with the --force option.
  • B.Manually delete the DB instance using the RDS console.
  • C.Disable termination protection on the EC2 instance.
  • D.Change the deletion policy of the DB instance to 'Delete' and then update the stack before deleting.
  • E.Modify the DB instance to allow deletion by setting DeletionProtection to false.

Why B: Manually deleting the retained DB instance removes the resource that is blocking the stack deletion. CloudFormation cannot delete a stack that contains a resource with a 'Retain' deletion policy until that resource is manually removed, as the stack expects the resource to no longer exist for the deletion to complete.

Variation 2. A company uses AWS CloudFormation to manage infrastructure. They have a template that creates an Amazon RDS DB instance. The template includes a 'DeletionPolicy' attribute set to 'Retain' on the DB instance resource. The DevOps team deletes the stack. Later, they notice that the DB instance still exists and is incurring costs. What is the MOST cost-effective way to remove the DB instance?

hard
  • A.Create a new CloudFormation stack that includes the same DB instance but with a DeletionPolicy of 'Delete', then delete that stack.
  • B.Manually delete the DB instance using the AWS Management Console or AWS CLI.
  • C.Use the 'aws cloudformation delete-change-set' command to remove the resource.
  • D.Update the stack: change the DeletionPolicy to 'Delete' and then delete the stack again.

Why B: The DB instance was created with a DeletionPolicy of 'Retain', which explicitly instructs CloudFormation to preserve the resource when the stack is deleted. Once the stack is deleted, CloudFormation no longer manages the DB instance, so the only way to remove it and stop costs is to manually delete it via the AWS Management Console or AWS CLI. This is the most cost-effective approach as it directly addresses the orphaned resource without unnecessary overhead.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This DOP-C02 practice question is part of Courseiva's free Amazon Web Services certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DOP-C02 exam.