A multi-tier application stores temporary data in S3 objects that are valid for 45 minutes and must be deleted after 24 hours. Each application version is deployed via a CloudFormation stack and when an older stack is deleted, CloudFormation fails to delete an S3 bucket, causing stack deletion to fail. Without major architectural changes, how can this be resolved?
Choose an answer
Tap an option to check your answer.
Correct answer: Implement a Lambda function that deletes all objects in the specified S3 bucket. Integrate that Lambda as a custom resource in the CloudFormation template, and add a DependsOn that references the S3 bucket resource..
Why this is the answer
The correct solution involves using a Lambda function as a CloudFormation custom resource to empty the S3 bucket before deletion. CloudFormation cannot delete an S3 bucket if it contains objects. A custom resource Lambda can be triggered during stack deletion to programmatically delete all objects, allowing CloudFormation to then successfully delete the now-empty bucket. The DependsOn attribute ensures the Lambda custom resource runs before the S3 bucket is deleted. Modifying the CloudFormation template to provision an Amazon EFS file system is a major architectural change, contrary to the problem statement. Adding an S3 Lifecycle rule to expire objects after 45 minutes doesn't guarantee the bucket will be empty at stack deletion, as objects might still exist. Adding a DeletionPolicy of Delete to the S3 bucket resource is the default behavior and will still fail if the bucket is not empty.
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