Object Lifecycle Management
Estimated time to read: 2 minutes
Object Lifecycle Management allows you to define automatic actions for objects stored in your bucket. These rules help you manage data retention and clean up unnecessary objects, improving storage efficiency.
Key Features of Lifecycle Management
- Automatic Expiration: Define policies to automatically delete objects after a certain period.
- Noncurrent Version Cleanup: If versioning is enabled, automatically remove old object versions.
- Incomplete Upload Cleanup: Ensure storage efficiency by automatically deleting unfinished multipart uploads.
- Flexible Rule Definition: Apply rules based on object prefixes, tags, or versions.
Interactions with versioning
Below are the interactions that happen based on Object Versioning enabled with the Expiration lifecycle policy.
Bucket Type | Expiration Action | Effect on Current Version | Effect on Noncurrent Versions |
---|---|---|---|
Nonversioned Bucket | Object is permanently deleted. | Object is removed. | N/A (No versioning). |
Versioning-Enabled | Delete marker is added. | Current version becomes noncurrent. | Noncurrent versions unchanged. |
Versioning-Enabled (If current version is a delete marker) |
No action taken. | Delete marker remains. | Noncurrent versions unchanged. |
Versioning-Enabled (If only version is a delete marker) |
Delete marker is removed. | Object is permanently deleted. | N/A (No other versions). |
Versioning-Suspended | Delete marker with null ID is added. | Delete marker replaces the object. | Object is deleted with null ID. |
Enable Lifecycle Policies
The following example policy deletes objects after 180 days:
{
"Rules": [
{
"ID": "DeleteAfter180Days",
"Prefix": "",
"Status": "Enabled",
"Expiration": {
"Days": 180
}
}
]
}
With the lifecycle policy stored as file lifecycle.json
it is possible to set this as our bucket lifecycle:
aws s3api put-bucket-lifecycle-configuration --bucket <bucket_name> --lifecycle-configuration file://lifecycle.json
See the lifecycle policy status of a bucket:
aws2 s3api get-bucket-lifecycle-configuration --bucket <bucket_name>
---
{
"Rules": [
{
"Expiration": {
"Days": 180
},
"ID": "DeleteAfter180Days",
"Prefix": "",
"Status": "Enabled"
}
]
}
Delete Lifecycle Policies
To remove all lifecycle policies from a bucket:
When deleting a bucket lifecycle policy, all previously created objects at the time of the policy will not be deleted at their deletion time.