AWS Certified DevOps Engineer – Professional (DOP-C02) — Question 8

An IT team has built an AWS CloudFormation template so others in the company can quickly and reliably deploy and terminate an application. The template creates an Amazon EC2 instance with a user data script to install the application and an Amazon S3 bucket that the application uses to serve static webpages while it is running.
All resources should be removed when the CloudFormation stack is deleted. However, the team observes that CloudFormation reports an error during stack deletion, and the S3 bucket created by the stack is not deleted.
How can the team resolve the error in the MOST efficient manner to ensure that all resources are deleted without errors?

Answer options

Correct answer: B

Explanation

The correct answer is B because it directly addresses the issue by ensuring the S3 bucket is emptied before deletion through a Lambda function. Option A is incorrect as simply adding a DeletionPolicy won't resolve existing issues with the bucket's contents. Option C involves manual intervention which is less efficient, and Option D complicates the architecture without addressing the specific deletion error.