class BucketAutoDeleteObjects
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.S3.Mixins.BucketAutoDeleteObjects |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awss3/mixins#BucketAutoDeleteObjects |
Java | software.amazon.awscdk.services.s3.mixins.BucketAutoDeleteObjects |
Python | aws_cdk.aws_s3.mixins.BucketAutoDeleteObjects |
TypeScript (source) | aws-cdk-lib » aws_s3 » mixins » BucketAutoDeleteObjects |
Implements
IMixin
Extends
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.
Example
// Apply mixins fluently with .with()
new s3.CfnBucket(scope, "MyL1Bucket")
.with(new BucketBlockPublicAccess())
.with(new BucketAutoDeleteObjects());
// Apply multiple mixins to the same construct
new s3.CfnBucket(scope, "MyL1Bucket")
.with(new BucketBlockPublicAccess(), new BucketAutoDeleteObjects());
// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
new s3.Bucket(stack, 'MyL2Bucket').with(new BucketBlockPublicAccess());
new CustomBucket(stack, 'MyCustomBucket').with(new BucketBlockPublicAccess());
Initializer
new BucketAutoDeleteObjects()
Methods
| Name | Description |
|---|---|
| apply | Applies the mixin functionality to the target construct. |
| supports(construct) | Determines whether this mixin can be applied to the given construct. |
applyTo(construct)
public applyTo(construct: IConstruct): void
Parameters
- construct
IConstruct
Applies the mixin functionality to the target construct.
supports(construct)
public supports(construct: IConstruct): boolean
Parameters
- construct
IConstruct
Returns
boolean
Determines whether this mixin can be applied to the given construct.

.NET
Go
Java
Python
TypeScript (