DEV Community

Cover image for Create S3 Lifecycle Rules with Tag Filters Using Python AWS CDK
chrishart0 for Signet Seal

Posted on

Create S3 Lifecycle Rules with Tag Filters Using Python AWS CDK

Get right to it, here is the code

Python CDK code for creating an S3 bucket with a lifecycle rule which uses a tag filter.

bucket = s3.Bucket(self, "myBucket",
    lifecycle_rules = [
        s3.LifecycleRule(
            id="example-rule-made-with-python-cdk",
            expiration=core.Duration.days(1),
            tag_filters={ 
                'Key': 'delete_in_1_day', 
                'Value': 'true'
            }
        )
    ]
)
Enter fullscreen mode Exit fullscreen mode

Relevant CDK docs:

Note: AWS Lifecycle rules do not get more precise than 24 hours[docs].

More CDK or AWS Serverless Questions?

Feel free to leave a comment here or hit us up on LinkedIn.

Want to learn more about how SignetSeal can help make your chats more secure? Read more about us on our website SignetSeal.com

Top comments (0)