Skip to content
v2.275.0

BucketAutoDeleteObjects 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 ​

ts
// 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());
python
# 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())
java
// Apply mixins fluently with .with()
// Apply mixins fluently with .with()
new CfnBucket(scope, "MyL1Bucket").with(new BucketBlockPublicAccess()).with(new BucketAutoDeleteObjects());

// Apply multiple mixins to the same construct
// Apply multiple mixins to the same construct
new CfnBucket(scope, "MyL1Bucket").with(new BucketBlockPublicAccess(), new BucketAutoDeleteObjects());

// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
new Bucket(stack, "MyL2Bucket").with(new BucketBlockPublicAccess());
new CustomBucket(stack, "MyCustomBucket").with(new BucketBlockPublicAccess());
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Apply mixins fluently with .with()
// Apply mixins fluently with .with()
new CfnBucket(scope, "MyL1Bucket").With(new BucketBlockPublicAccess()).With(new BucketAutoDeleteObjects());

// Apply multiple mixins to the same construct
// Apply multiple mixins to the same construct
new CfnBucket(scope, "MyL1Bucket").With(new BucketBlockPublicAccess(), new BucketAutoDeleteObjects());

// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
new Bucket(stack, "MyL2Bucket").With(new BucketBlockPublicAccess());
new CustomBucket(stack, "MyCustomBucket").With(new BucketBlockPublicAccess());
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Apply mixins fluently with .with()
// Apply mixins fluently with .with()
s3.NewCfnBucket(scope, jsii.String("MyL1Bucket")).With(awscdk.NewBucketBlockPublicAccess()).With(awscdk.NewBucketAutoDeleteObjects())

// Apply multiple mixins to the same construct
// Apply multiple mixins to the same construct
s3.NewCfnBucket(scope, jsii.String("MyL1Bucket")).With(awscdk.NewBucketBlockPublicAccess(), awscdk.NewBucketAutoDeleteObjects())

// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
// Mixins work with all types of constructs:
// L1, L2 and even custom constructs
s3.NewBucket(stack, jsii.String("MyL2Bucket")).With(awscdk.NewBucketBlockPublicAccess())
newCustomBucket(stack, jsii.String("MyCustomBucket")).With(awscdk.NewBucketBlockPublicAccess())

Initializer ​

ts
new BucketAutoDeleteObjects()
python
BucketAutoDeleteObjects()
java
new BucketAutoDeleteObjects()
csharp
new BucketAutoDeleteObjects()
go
NewBucketAutoDeleteObjects()

Methods ​

applyTo(construct: IConstruct): voiddef apply_to(self, construct: IConstruct) -> Nonepublic void applyTo(IConstruct construct)public void ApplyTo(IConstruct construct)func ApplyTo(Construct IConstruct)#
Applies the mixin functionality to the target construct.
isMixin(x: any): boolean@staticmethod def is_mixin(x: Any) -> boolpublic static Boolean isMixin(Object x)public static bool IsMixin(object x)func IsMixin(X interface{}) *boolstatic#
Checks if `x` is a Mixin.
1 parameter · returns

Parameters

  • xxxxX — Any object.

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

supports(construct: IConstruct): booleandef supports(self, construct: IConstruct) -> boolpublic Boolean supports(IConstruct construct)public bool Supports(IConstruct construct)func Supports(Construct IConstruct) *bool#
Determines whether this mixin can be applied to the given construct.