DOP-C02 · Question #250
A company has developed a static website hosted on an Amazon S3 bucket. The website is deployed using AWS CloudFormation. The CloudFormation template defines an S3 bucket and a custom resource that…
The correct answer is B. Deletion has failed because the S3 bucket is not empty. Modify the custom resource's AWS. Explanation Option B is correct because AWS CloudFormation cannot delete an S3 bucket that contains objects - this is a fundamental AWS constraint. Since the custom resource copied content into the bucket, the bucket is non-empty when CloudFormation attempts deletion. The fix…
Question
A company has developed a static website hosted on an Amazon S3 bucket. The website is deployed using AWS CloudFormation. The CloudFormation template defines an S3 bucket and a custom resource that copies content into the bucket from a source location. The company has decided that it needs to move the website to a new location, so the existing CloudFormation stack must be deleted and re-created. However, CloudFormation reports that the stack could not be deleted cleanly. What is the MOST likely cause and how can the DevOps engineer mitigate this problem for this and future versions of the website?
Options
- ADeletion has failed because the S3 bucket has an active website configuration. Modify the
- BDeletion has failed because the S3 bucket is not empty. Modify the custom resource's AWS
- CDeletion has failed because the custom resource does not define a deletion policy. Add a
- DDeletion has failed because the S3 bucket is not empty. Modify the S3 bucket resource in the
How the community answered
(49 responses)- A8% (4)
- B84% (41)
- C6% (3)
- D2% (1)
Explanation
Explanation
Option B is correct because AWS CloudFormation cannot delete an S3 bucket that contains objects - this is a fundamental AWS constraint. Since the custom resource copied content into the bucket, the bucket is non-empty when CloudFormation attempts deletion. The fix is to modify the custom resource's Lambda function to handle the Delete event by emptying the bucket before CloudFormation attempts to remove it, ensuring clean deletions for this and all future stack versions.
Why the distractors are wrong:
- Option A is incorrect because a static website configuration alone does not prevent bucket deletion - the bucket being non-empty is the actual blocker.
- Option C is incorrect because a missing deletion policy on the custom resource is not the root cause; the issue is the bucket's contents, not the resource's lifecycle policy.
- Option D is partially related but points to modifying the S3 bucket resource itself (e.g., using a
DeletionPolicy) rather than the custom resource, which is the correct place to handle cleanup since it was responsible for putting the content there in the first place.
Memory Tip: Think of it this way - "whoever makes the mess cleans it up." The custom resource populated the bucket, so its Delete handler should empty it. CloudFormation never deletes a non-empty S3 bucket, no exceptions.
Topics
Community Discussion
No community discussion yet for this question.