BucketAutoDeleteObjects
- class aws_cdk.aws_s3.mixins.BucketAutoDeleteObjects
Bases:
MixinS3-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
removalPolicyto be set toRemovalPolicy.DESTROY.Apply this mixin to a bucket will add
s3:PutBucketPolicyto the bucket policy. This is because during bucket deletion, the custom resource provider needs to update the bucket policy by adding a deny policy fors3:PutObjectto 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
xis a Mixin.- Parameters:
x (
Any) – Any object.- Return type:
bool- Returns:
true if
xis an object created from a class which extendsMixin.