DVA-C02 Development with AWS Services Practice Question
A developer is creating a CloudFormation template to deploy an Amazon S3 bucket. The developer wants the bucket to be deleted automatically when the CloudFormation stack is deleted. What should the developer specify in the template?
⚠ Common exam trap
It's easy for candidates to confuse `DeletionPolicy` with `UpdatePolicy` or assume that `Retain` is the default, leading them to choose Option D, when in fact `Delete` is the default and correct choice for automatic deletion.
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
✓
Set the DeletionPolicy attribute to Delete.
The `DeletionPolicy` attribute in AWS CloudFormation controls what happens to a resource when its stack is deleted. By setting `DeletionPolicy: Delete` on the S3 bucket resource, the developer ensures that the bucket is automatically deleted when the stack is deleted. This is the default behavior for most resources, but explicitly setting it confirms the intent and overrides any other policy like `Retain`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Set the DeletionPolicy attribute to Delete.
Why this is correct
When a CloudFormation stack is deleted, resources with DeletionPolicy: Delete are removed from the AWS account. For an S3 bucket, applying DeletionPolicy: Delete ensures that the bucket and all its contents are permanently deleted when the associated CloudFormation stack is terminated. This is the correct approach to ensure the bucket's lifecycle is tied directly to the stack's lifecycle, preventing orphaned resources. This attribute explicitly instructs CloudFormation to remove the resource.
- ✗
Specify a unique bucket name to avoid conflicts.
Why it's wrong here
While specifying a globally unique S3 bucket name is a fundamental requirement for creating any S3 bucket, it solely addresses potential naming conflicts during resource creation. The uniqueness of a bucket's name has no bearing on its deletion behavior or whether it will be removed when its containing CloudFormation stack is deleted. This action is necessary for successful deployment but irrelevant to the deletion policy.
- ✗
Use the DependsOn attribute to specify the bucket depends on the stack.
Why it's wrong here
The DependsOn attribute in CloudFormation is used to explicitly define the creation order of resources within a stack, ensuring that a dependent resource is not created until its dependencies are fully provisioned. However, DependsOn does not influence or dictate the deletion behavior of a resource. It only manages the provisioning sequence, not the de-provisioning policy, making it ineffective for controlling bucket deletion upon stack removal.
- ✗
Set the DeletionPolicy attribute to Retain.
Why it's wrong here
Setting the DeletionPolicy attribute to Retain explicitly instructs CloudFormation to preserve the resource even after the stack that created it has been deleted. For an S3 bucket, this means the bucket and its contents would remain in the AWS account, becoming an orphaned resource, which is contrary to the goal of ensuring the bucket is deleted along with the stack. This policy is typically used for critical data stores.
Quick reference
AWS S3 Storage Class Comparison
| Storage Class | Min Duration | Retrieval | Use Case |
|---|---|---|---|
| S3 Standard | None | Immediate | Frequently accessed data |
| S3 Standard-IA | 30 days | Immediate | Infrequent access, rapid retrieval |
| S3 One Zone-IA | 30 days | Immediate | Non-critical infrequent data |
| S3 Intelligent-Tiering | None | Immediate–hours | Unknown or changing access patterns |
| S3 Glacier Instant | 90 days | Milliseconds | Archive with instant retrieval |
| S3 Glacier Flexible | 90 days | Minutes–hours | Archive, flexible retrieval |
| S3 Glacier Deep Archive | 180 days | Hours | Long-term compliance archive |
Go deeper
Related to this question
About these practice questions
This DVA-C02 question is part of Courseiva's 724-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DVA-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 DVA-C02 exam.