Creating a lifecycle management policy

You can manage a bucket lifecycle policy configuration using standard S3 operations rather than using the radosgw-admin command. RADOS Gateway supports only a subset of the Amazon S3 API policy language applied to buckets. The lifecycle configuration contains one or more rules defined for a set of bucket objects.

Prerequisites

  • A running IBM Storage Ceph cluster.

  • Installation of the Ceph Object Gateway.

  • Root-level access to a Ceph Object Gateway node.

  • An S3 bucket created.

  • An S3 user created with user access.

  • Access to a Ceph Object Gateway client with the AWS CLI package installed.

Procedure

  1. Create a JSON file for lifecycle configuration:

    Example

    [user@client ~]$ vi lifecycle.json
  2. Add the specific lifecycle configuration rules in the file:

    Example

    {
            "Rules": [
            {
                        "Filter": {
                                "Prefix": "images/"
                        },
                        "Status": "Enabled",
                        "Expiration": {
                                "Days": 1
                        },
                        "ID": "ImageExpiration"
                }
        ]
    }

    The lifecycle configuration example expires objects in the images directory after 1 day.

  3. Set the lifecycle configuration on the bucket:

    Syntax

    aws --endpoint-url=_RADOSGW_ENDPOINT_URL_:PORT s3api put-bucket-lifecycle-configuration --bucket _BUCKET_NAME_ --lifecycle-configuration file://_PATH_TO_LIFECYCLE_CONFIGURATION_FILE_/_LIFECYCLE_CONFIGURATION_FILE_.json

    Example

    [user@client ~]$ aws --endpoint-url=http://host01:80 s3api put-bucket-lifecycle-configuration --bucket testbucket --lifecycle-configuration file://lifecycle.json

    In this example, the lifecycle.json file exists in the current directory.

  • Retrieve the lifecycle configuration for the bucket:

    Syntax

    aws --endpoint-url=_RADOSGW_ENDPOINT_URL_:PORT s3api get-bucket-lifecycle-configuration --bucket _BUCKET_NAME_

    Example

    [user@client ~]$ aws --endpoint-url=http://host01:80 s3api get-bucket-lifecycle-configuration --bucket testbucket
    {
            "Rules": [
            {
                        "Expiration": {
                                "Days": 1
                        },
                        "ID": "ImageExpiration",
                        "Filter": {
                                "Prefix": "images/"
                        },
                        "Status": "Enabled"
                }
        ]
    }
  • Optional: From the Ceph Object Gateway node, log into the cephadm shell and retrieve the bucket lifecycle configuration:

    Syntax

    radosgw-admin lc get --bucket=BUCKET_NAME

    Example

    [ceph: root@host01 /]# radosgw-admin lc get --bucket=testbucket
    {
            "prefix_map": {
                    "images/": {
                            "status": true,
                            "dm_expiration": false,
                            "expiration": 1,
                            "noncur_expiration": 0,
                            "mp_expiration": 0,
                            "transitions": {},
                            "noncur_transitions": {}
                    }
            },
            "rule_map": [
            {
                    "id": "ImageExpiration",
                    "rule": {
                            "id": "ImageExpiration",
                            "prefix": "",
                            "status": "Enabled",
                            "expiration": {
                                    "days": "1",
                                    "date": ""
                            },
                            "mp_expiration": {
                                    "days": "",
                                    "date": ""
                            },
                            "filter": {
                                    "prefix": "images/",
                                    "obj_tags": {
                                            "tagset": {}
                                    }
                            },
                            "transitions": {},
                            "noncur_transitions": {},
                            "dm_expiration": false
                    }
            }
      ]
    }