BucketAutoDeleteObjects

class aws_cdk.aws_s3.mixins.BucketAutoDeleteObjects

Bases: Mixin

S3-specific Mixin to automatically delete all objects from a bucket when the bucket is removed from the stack or when the stack is deleted.

Requires the removalPolicy to be set to RemovalPolicy.DESTROY.

Apply this mixin to a bucket will add s3:PutBucketPolicy to the bucket policy. This is because during bucket deletion, the custom resource provider needs to update the bucket policy by adding a deny policy for s3:PutObject to prevent race conditions with external bucket writers.

ExampleMetadata:

fixture=README-mixins infused

Example:

# Apply mixins fluently with .with()
s3.CfnBucket(scope, "MyL1Bucket").with(BucketBlockPublicAccess()).with(BucketAutoDeleteObjects())

# Apply multiple mixins to the same construct
s3.CfnBucket(scope, "MyL1Bucket").with(BucketBlockPublicAccess(), BucketAutoDeleteObjects())

# Mixins work with all types of constructs:
# L1, L2 and even custom constructs
s3.Bucket(stack, "MyL2Bucket").with(BucketBlockPublicAccess())
CustomBucket(stack, "MyCustomBucket").with(BucketBlockPublicAccess())

Methods

apply_to(construct)

Applies the mixin functionality to the target construct.

Parameters:

construct (IConstruct)

Return type:

None

supports(construct)

Determines whether this mixin can be applied to the given construct.

Parameters:

construct (IConstruct)

Return type:

bool

Static Methods

classmethod is_mixin(x)

Checks if x is a Mixin.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Mixin.