Automatic object removal via AWS CLI
Lifecycle policies in CDB Object Storage automatically delete objects after a configured number of days, following the AWS S3 lifecycle configuration standard.
Lifecycle policy logic
Object removal runs around midnight UTC. Three conditions govern deletion timing:
-
Lifecycle policy set before upload. If the policy is set for 1 day and the object is uploaded on January 2, it is removed on January 4.
-
Lifecycle policy set after upload. If an object is uploaded on January 1 (at any time) and a 1-day expiration policy is then applied, the object is deleted on January 3.
-
Lifecycle policy removed. Deleting the lifecycle policy from the bucket stops automatic removal — objects already in the bucket are kept.
Lifecycle configuration elements
AWS CLI uses a JSON configuration file. The file structure is:
{
"Rules": [
{
"ID": "...",
"Prefix": "",
"Status": "Enabled",
"Expiration": {
"Days": ...
}
}
]
}
| Field | Description |
|---|---|
ID | Unique rule identifier — up to 255 characters, letters, digits, and underscores. |
Prefix | Leave empty to apply the rule to the entire bucket; specify a folder name to scope the rule to that folder only. |
Status | "Enabled" activates the rule; "Disabled" suspends it without deleting it. |
Expiration.Days | Number of days after which objects are automatically deleted. |
AWS CLI lifecycle management
AWS CLI provides three commands for managing lifecycle policies: put-bucket-lifecycle to apply a policy, get-bucket-lifecycle-configuration to verify it, and delete-bucket-lifecycle to remove it.
Applying a lifecycle policy
- 1
Create the configuration file
Create a
lifecycle.jsonfile with the following content:{ "Rules": [ { "ID": "one_day", "Prefix": "", "Status": "Enabled", "Expiration": { "Days": 1 } } ] }Parameter Description one_dayRule ID. ""(empty prefix)The rule applies to the entire bucket. "Enabled"The rule is active. 1Objects are deleted after 1 day. To apply the rule to a specific folder, set
"Prefix"to the folder name:"Prefix": "deleteme/". - 2
Apply the policy
Run the following command from the directory containing
lifecycle.json, replacing the placeholder values:aws s3api put-bucket-lifecycle --bucket my-bucket --lifecycle-configuration file://lifecycle.json --endpoint-url=https://<storage-hostname>Parameter Description my-bucketThe name of the bucket. <storage-hostname>The storage endpoint hostname from the Details section in the CDB Technical Web Portal — all hostnames are listed in S3 URLs. - 3
Verify the configuration
Run the following command to check the current lifecycle configuration:
aws s3api get-bucket-lifecycle-configuration --bucket my-bucket --endpoint-url=https://<storage-hostname>The response contains the applied policy as JSON.
Deleting a lifecycle policy
Run the following command to remove the lifecycle policy from the bucket:
aws s3api delete-bucket-lifecycle --bucket my-bucket --endpoint-url=https://<storage-hostname>
| Parameter | Description |
|---|---|
my-bucket | The name of the bucket. |
<storage-hostname> | The storage endpoint hostname. |