Bucket lifecycle

Amazon S3 SDK also provides an API for managing the lifecycle of a bucket. It has two ways to manage the objects of the bucket:

  • Transition
  • Removal

The transition method moves the data to Amazon Glacier, whereas the removal method removes the data from Amazon S3.

To add the lifecycle, we need to apply rules to the bucket. We can apply multiple rules to a single bucket. Let's see how we create rules:

 private Rule createRule(String id, String prefix, int days){ Rule rule = new Rule(); rule.withId(id); rule.withPrefix(prefix); /** * Transition is to archive objects into Amazon Glacier. */ rule.withTransition(new Transition() .withDays(days) .withStorageClass(StorageClass.Glacier)); rule.withStatus(BucketLifecycleConfiguration.ENABLED.toString()); ...

Get Amazon S3 Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.