A static website is hosted in an S3 bucket and deployed via CloudFormation. The template creates the S3 bucket and a custom resource that copies site content into the bucket from a source. The team needs to delete and recreate the stack to move the website, but CloudFormation fails to delete the stack cleanly. What is the most likely cause, and how should the engineer prevent this for current and future site versions?
Choose an answer
Tap an option to check your answer.
Correct answer: Deletion failed because the S3 bucket is not empty. Update the Lambda backing the custom resource to recursively empty the bucket when RequestType is Delete..
Why this is the answer
When a CloudFormation stack is deleted, S3 buckets that are not empty will prevent stack deletion by default. The custom resource, backed by a Lambda function, is responsible for copying content into the bucket. To ensure clean stack deletion, the Lambda function associated with the custom resource should be modified to handle the Delete RequestType. This modification involves adding logic to recursively empty the S3 bucket before the bucket itself is deleted. The other options are incorrect because: Removing the WebsiteConfiguration property is irrelevant to bucket deletion when it contains objects. Custom resources do not have a DeletionPolicy property in the same way other resources do; their deletion behavior is controlled by the backing Lambda function. An S3 bucket resource in CloudFormation does not have a DeletionPolicy of Empty; the standard DeletionPolicy values are Delete, Retain, or Snapshot.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed