DEV Community

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

Posted on

3 2

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

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay