nerdexam
Amazon

SAP-C02 · Question #861

A company uses an AWS CloudFormation template to deploy an Amazon ECS service into a production environment. The template includes an Amazon S3 bucket that is named by using a common prefix with the…

The correct answer is A. Associate an AWS Lambda function with a CloudFormation custom resource to delete all keys that D. Ensure that CloudFormation operations are being invoked by a role that has s3:DeleteObject. CloudFormation cannot delete a nonempty S3 bucket by default. Associating a Lambda function with a custom resource allows all objects in the bucket to be deleted before the stack deletion. Additionally, ensuring that the role used for CloudFormation has s3:DeleteObject…

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

Question

A company uses an AWS CloudFormation template to deploy an Amazon ECS service into a production environment. The template includes an Amazon S3 bucket that is named by using a common prefix with the CloudFormation stack name. The company uses the same template to create temporary environments for development and continuous integration. Developers can create environments successfully, but they receive errors from CloudFormation when they attempt to delete the environments. The developers often need to delete and recreate stacks with the same names as part of the development and testing process. Which combination of steps should a solutions architect take to modify the solution to resolve this issue? (Choose two.)

Options

  • AAssociate an AWS Lambda function with a CloudFormation custom resource to delete all keys that
  • BModify the S3 bucket resource in the CloudFormation template by specifying Delete for the
  • CModify the S3 bucket resource in the CloudFormation template by specifying Retain for the
  • DEnsure that CloudFormation operations are being invoked by a role that has s3:DeleteObject
  • EModify the S3 bucket resource in the CloudFormation template to configure a bucket policy that

How the community answered

(24 responses)
  • A
    75% (18)
  • B
    8% (2)
  • C
    13% (3)
  • E
    4% (1)

Explanation

CloudFormation cannot delete a nonempty S3 bucket by default. Associating a Lambda function with a custom resource allows all objects in the bucket to be deleted before the stack deletion. Additionally, ensuring that the role used for CloudFormation has s3:DeleteObject permissions is required so that the Lambda function or CloudFormation can remove objects, enabling successful

Community Discussion

No community discussion yet for this question.

Full SAP-C02 Practice