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()); return rule; }
There are some rules that need to be applied to the bucket lifecycle configuration. Multiple rules can be applied to a bucket. Rules can be formed with several parameters...