Why it matters
Buckets that are written often can hold many times more data in old versions than in current objects.How nOps finds it
nOps uses S3 Storage Lens metrics for each bucket: the bytes held by noncurrent versions. The saving is that storage at the bucket’s billed Standard storage rate. Storage Lens does not show how old the versions are, so the estimate is an upper bound for a 90-day rule.Before you start
S3 Storage Lens metrics for the bucket, and permission to update lifecycle rules (s3:GetLifecycleConfiguration, s3:PutLifecycleConfiguration). Know your recovery and compliance requirements for old versions.
How to implement
- Check versioning and Object Lock on the bucket:
aws s3api get-bucket-versioning --bucket BUCKET. - Decide how long you need old versions for recovery, for example 90 days.
- Save the current lifecycle rules, then add a rule with Permanently delete noncurrent versions of objects after that many days (
NoncurrentVersionExpirationwithNoncurrentDays), keeping every existing rule. - Write back the full merged configuration with
put-bucket-lifecycle-configuration, since it replaces every rule. - Update Terraform or CloudFormation with the same rule.
Risks and considerations
- Expired versions are deleted permanently, so you can no longer restore objects to those versions.
- Current versions are never affected.
- Object Lock retention still applies; locked versions are not deleted until their retention ends.
- To roll back, restore the saved lifecycle rules. Versions already expired cannot be recovered.