Get the lifecycle configuration of an Amazon S3 bucket using an Amazon SDK - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Get the lifecycle configuration of an Amazon S3 bucket using an Amazon SDK

The following code example shows how to get the lifecycle configuration of an S3 bucket.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

class BucketWrapper: """Encapsulates S3 bucket actions.""" def __init__(self, bucket): """ :param bucket: A Boto3 Bucket resource. This is a high-level resource in Boto3 that wraps bucket actions in a class-like structure. """ self.bucket = bucket self.name = bucket.name def get_lifecycle_configuration(self): """ Get the lifecycle configuration of the bucket. :return: The lifecycle rules of the specified bucket. """ try: config = self.bucket.LifecycleConfiguration() logger.info( "Got lifecycle rules %s for bucket '%s'.", config.rules, self.bucket.name) except: logger.exception( "Couldn't get lifecycle rules for bucket '%s'.", self.bucket.name) raise else: return config.rules

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.