0
votes

I'm beginner to aws cdk, I have implemented S3 lifecycle management using AWS CDK to delete bucket (including files) after 10 days of bucket creation.

Cdk implementation as below:

Builder builder = BucketProps.builder().encryption(BucketEncryption.KMS_MANAGED).removalPolicy(RemovalPolicy.DESTROY);

final String bucketName = ApplicationProperties.INSTANCE.getBatchS3Name();
final List<LifecycleRule> lifecycleRules = new ArrayList();
final LifecycleRule rule = new LifecycleRule.Builder().expiration(Duration.days(10)).build();
lifecycleRules.add(rule);
builder.lifecycleRules(lifecycleRules);

this.bucket = new Bucket(stack, "BatchWorkBucket", builder.build());

But s3 object is not getting deleted after 10 days. It is getting expired as shown in attached image. We don't have option to setup "Delete expired delete markers or incomplete multipart uploads" or other options in cdk api (https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-s3.LifecycleRule.html#transitions).

Could you please help me on this subject, how to delete s3 object using aws cdk.

enter image description here

1

1 Answers

0
votes

I believe this is working as expected. The objects marked as expired will eventually be deleted, but not exactly after the 10 days, like in your case. As per documentation:

When an object reaches the end of its lifetime based on its lifecycle policy, Amazon S3 queues it for removal and removes it asynchronously. There might be a delay between the expiration date and the date at which Amazon S3 removes an object.