AWS Certified Developer – Associate / Question #744 of 557

Question #744

A development team uses AWS CloudFormation to manage a web application that includes an Amazon S3 bucket for critical data storage. During a recent stack update, a developer accidentally caused the S3 bucket to be deleted and recreated, resulting in data loss. The team needs to prevent such accidental deletions in the future. Which solutions will meet these requirements? (Choose two.)

A

Add a CloudFormation DeletionPolicy attribute with the Retain value to the S3 bucket resource.

B

Update the CloudFormation stack policy to prevent updates to the S3 bucket.

C

Enable versioning on the S3 bucket to preserve object history.

D

Create a CloudFormation stack set for managing the S3 bucket across environments.

E

Modify the S3 bucket policy to restrict delete actions via IAM policies.

Explanation

The correct answers are A and B.

- A: The DeletionPolicy attribute with Retain ensures that CloudFormation retains the S3 bucket (instead of deleting it) during stack updates or deletions. This directly prevents accidental data loss.
- B: A CloudFormation stack policy can explicitly deny updates to the S3 bucket resource, preventing modifications or deletions during stack updates.

Other options are incorrect because:
- C: Versioning preserves object history but does not prevent the bucket itself from being deleted.
- D: Stack sets manage deployments across environments but do not prevent resource deletion during stack updates.
- E: S3 bucket policies restrict IAM users, but CloudFormation uses its own permissions (via the IAM role executing the stack) to delete resources, making this ineffective.

Key Points: Use DeletionPolicy: Retain to retain critical resources and stack policies to block destructive updates. Versioning and bucket policies address object-level protection, not bucket deletion.

Answer

The correct answer is: AB