A company runs an application on EC2 and Lambda that stores temporary objects in Amazon S3; objects are deleted after 24 hours. The company deploys new application versions by creating CloudFormation stacks for the required resources and deletes the old stack after validation. Recently deletion of an old development stack failed. A solutions architect must resolve the deletion failure without major architectural changes. Which solution meets this requirement?
Choose an answer
Tap an option to check your answer.
Correct answer: Create an AWS Lambda function that deletes objects from the S3 bucket, add that Lambda as a CloudFormation custom resource, and include a DependsOn attribute referencing the S3 bucket resource so the custom resource runs during stack deletion..
Why this is the answer
The correct solution addresses the common CloudFormation stack deletion failure when an S3 bucket is not empty. CloudFormation cannot delete an S3 bucket with objects in it by default. Creating a Lambda function as a custom resource allows you to execute custom logic during stack operations, including deletion. By referencing the S3 bucket with DependsOn, the Lambda function will be invoked to empty the bucket before CloudFormation attempts to delete the S3 resource, thus enabling successful stack deletion. Changing the DeletionPolicy to Delete or Snapshot would not resolve the issue; Delete would still fail on a non-empty bucket, and Snapshot is not applicable to S3 buckets. Modifying the architecture to use EFS is a major change and does not address the immediate problem of deleting the existing S3 bucket.
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