nerdexam
Amazon

SAP-C02 · Question #798

A company runs an application on Amazon EC2 and AWS Lambda. The application stores temporary data in Amazon S3. The S3 objects are deleted after 24 hours. The company deploys new versions of the…

The correct answer is A. Create a Lambda function to delete objects from the S3 bucket. Add the Lambda function as a. Implementing a CloudFormation custom resource that triggers a Lambda function upon stack deletion allows the S3 bucket to be emptied programmatically before CloudFormation attempts to delete the bucket, preventing deletion failures.

Submitted by deeparc· Mar 6, 2026Continuous Improvement for Existing Solutions

Question

A company runs an application on Amazon EC2 and AWS Lambda. The application stores temporary data in Amazon S3. The S3 objects are deleted after 24 hours. The company deploys new versions of the application by launching AWS CloudFormation stacks. The stacks create the required resources. After validating a new version, the company deletes the old stack. The deletion of an old development stack recently failed. A solutions architect needs to resolve this issue without major architecture changes. Which solution will meet these requirements?

Options

  • ACreate a Lambda function to delete objects from the S3 bucket. Add the Lambda function as a
  • BModify the CloudFormation stack to attach a DeletionPolicy attribute with a value of Delete to the
  • CUpdate the CloudFormation stack to add a DeletionPolicy attribute with a value of Snapshot for
  • DUpdate the CloudFormation template to create an Amazon EFS file system to store temporary

How the community answered

(33 responses)
  • A
    82% (27)
  • B
    6% (2)
  • C
    9% (3)
  • D
    3% (1)

Why each option

Implementing a CloudFormation custom resource that triggers a Lambda function upon stack deletion allows the S3 bucket to be emptied programmatically before CloudFormation attempts to delete the bucket, preventing deletion failures.

ACreate a Lambda function to delete objects from the S3 bucket. Add the Lambda function as aCorrect

A CloudFormation custom resource invoking a Lambda function during stack deletion can programmatically empty the S3 bucket, resolving the dependency issue that prevents CloudFormation from deleting a non-empty bucket without major architectural changes.

BModify the CloudFormation stack to attach a DeletionPolicy attribute with a value of Delete to the

The `DeletionPolicy: Delete` is the default behavior and does not address the underlying issue of an S3 bucket failing to delete if it contains objects.

CUpdate the CloudFormation stack to add a DeletionPolicy attribute with a value of Snapshot for

`DeletionPolicy: Snapshot` or `Retain` is used to preserve a resource or its data upon stack deletion, not to facilitate the deletion of a non-empty S3 bucket.

DUpdate the CloudFormation template to create an Amazon EFS file system to store temporary

Replacing S3 with Amazon EFS constitutes a major architectural change, which goes against the problem's requirement to resolve the issue without such changes.

Concept tested: CloudFormation custom resources for S3 bucket lifecycle management and stack deletion

Source: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html

Community Discussion

No community discussion yet for this question.

Full SAP-C02 Practice