Configure Lifecycle Policies on S3 buckets

Solution Verified - Updated

Environment

Red Hat OpenShift Container Platform (RHOCP) v4.x
Red Hat OpenShift Data Foundations (RHODF) v4.14+

Issue

  • How to configure a Lifecycle Policy for a Noobaa bucket
  • How to configure a Lifecycle Policy for an RGW bucket

Resolution

  1. Create a bucket-lifecycle file called "lifecycle.json" with the following:
    NOTE: change the 'Days' ({n}) to match how long you want to keep files in the bucket for
    1 days means noobaa/rgw will purge ALL objects older than a day.
{
"Rules": [
    {
        "Expiration": {
            "Days": {n}
        },
        "ID": "data-expire-withoutprefix",
        "Filter": {
            "Prefix": ""
        },
        "Status": "Enabled"
    }
]
}
  1. Gather the secret key, access key, and endpoint URL from the proper secrets (oc get secrets) in your cluster.
  2. Create an alias for the s3 cmd to keep track of the secret and access keys:
alias s3api-120='AWS_ACCESS_KEY_ID=<access_key> AWS_SECRET_ACCESS_KEY=<secret_key> aws s3api --no-verify-ssl --endpoint-url <endpoint>'
  1. Apply the lifecycle policy to the bucket:
s3api-120 put-bucket-lifecycle-configuration --bucket <bucket> --lifecycle-configuration file://lifecycle.json
  1. Double check the policy was applied:
s3api-120 get-bucket-lifecycle-configuration --bucket <bucket>                                             
{
"Rules": [
    {
        "Expiration": {
            "Days": 1
        },
        "ID": "data-expire-withoutprefix",
        "Filter": {
            "Prefix": ""
        },
        "Status": "Enabled"
    }
]
}

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.