---
title: "Lifecycle rules"
description: "Delete a bucket's objects after a number of days or on a date, delete noncurrent versions, and abort unfinished multipart uploads sooner."
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.ezghcloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle rules

A lifecycle rule deletes a bucket's objects by age or on a date, deletes noncurrent versions, removes
expired delete markers, or aborts its unfinished multipart uploads. A bucket has up to 100 rules.

| Field | Value |
| --- | --- |
| ID | Up to 255 characters, unique in the bucket. Left out, one is assigned. IDs starting `ezgh-` are reserved |
| Status | Enabled or disabled. A disabled rule does nothing |
| Prefix | The keys the rule applies to, up to 1,024 bytes. Empty for the whole bucket |
| Delete objects | After a number of days since the object was last written, 1 or more, or on a date, at midnight UTC |
| Delete noncurrent versions | After a number of days since a newer version replaced them, 1 or more |
| Remove expired delete markers | Yes or No. A delete marker is removed once it's the only version left of its object. Not in a rule that deletes objects |
| Abort unfinished multipart uploads | After 1 to 7 days since the upload began |

A rule has one or more actions.

- In a bucket with [versioning](/object-storage/versioning) enabled, **Delete objects** adds a delete
  marker and keeps the earlier versions. The two version actions do nothing in a bucket that never
  had versioning.
- The abort action applies to the whole bucket: its rule takes no prefix, and a bucket has one such
  rule.
- Unfinished multipart uploads are always aborted after 7 days, with or without a rule.

> **Caution**
>
> Objects are deleted within a day after they qualify. Deletion is permanent.

## Console

Changing rules needs `objects.buckets.update` and `objects.objects.delete`.

1. Open the bucket and select **Lifecycle**.
2. Select **Create rule**.
3. Enter a prefix, or leave it empty for the whole bucket.
4. Under **Delete objects**, choose **After a number of days** or **On a date**, or enter the days
   under **Abort unfinished uploads after (days)**.
5. For a bucket with versioning, enter the days under **Delete noncurrent versions after (days)**, or
   select **Remove expired delete markers**.
6. Select **Save rule**. A rule that deletes objects asks you to confirm.

Select a rule to edit, disable or delete it. Deleting a rule brings back nothing it removed.

## AWS CLI

`put-bucket-lifecycle-configuration` replaces every rule of the bucket. This sets two: objects under
`logs/` are deleted after 30 days, and unfinished multipart uploads are aborted after 2.

```json title="lifecycle.json"
{
  "Rules": [
    {
      "ID": "expire-logs",
      "Status": "Enabled",
      "Filter": { "Prefix": "logs/" },
      "Expiration": { "Days": 30 }
    },
    {
      "ID": "abort-uploads",
      "Status": "Enabled",
      "Filter": { "Prefix": "" },
      "AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 2 }
    }
  ]
}
```

```sh
export AWS_PROFILE=ezgh

aws s3api put-bucket-lifecycle-configuration --bucket my-bucket --lifecycle-configuration file://lifecycle.json
aws s3api get-bucket-lifecycle-configuration --bucket my-bucket
aws s3api delete-bucket-lifecycle --bucket my-bucket
```

This rule deletes noncurrent versions 30 days after a newer version replaces them, and removes
expired delete markers:

```json
{
  "ID": "expire-versions",
  "Status": "Enabled",
  "Filter": { "Prefix": "" },
  "NoncurrentVersionExpiration": { "NoncurrentDays": 30 },
  "Expiration": { "ExpiredObjectDeleteMarker": true }
}
```

`get-bucket-lifecycle-configuration` answers `NoSuchLifecycleConfiguration` for a bucket with no
rules. See [AWS CLI](/object-storage/aws-cli) for the profile.

## boto3

With the client from [boto3](/object-storage/boto3):

```python
s3.put_bucket_lifecycle_configuration(
    Bucket="my-bucket",
    LifecycleConfiguration={
        "Rules": [
            {
                "ID": "expire-logs",
                "Status": "Enabled",
                "Filter": {"Prefix": "logs/"},
                "Expiration": {"Days": 30},
            },
            {
                "ID": "abort-uploads",
                "Status": "Enabled",
                "Filter": {"Prefix": ""},
                "AbortIncompleteMultipartUpload": {"DaysAfterInitiation": 2},
            },
        ]
    },
)

rules = s3.get_bucket_lifecycle_configuration(Bucket="my-bucket")["Rules"]

s3.delete_bucket_lifecycle(Bucket="my-bucket")
```

## CLI

`ezgh objects buckets lifecycle` needs `ezgh` 0.61.0 or later, and 0.71.0 or later for the two
version fields. `put` replaces every rule with those
in a JSON file:

```json title="rules.json"
{
  "rules": [
    { "id": "expire-logs", "status": "enabled", "prefix": "logs/", "expirationDays": 30 },
    { "id": "abort-uploads", "status": "enabled", "abortIncompleteMultipartUploadDays": 2 },
    { "id": "expire-versions", "status": "enabled", "noncurrentVersionExpirationDays": 30, "expiredObjectDeleteMarker": true }
  ]
}
```

```sh
ezgh objects buckets lifecycle put my-bucket --file rules.json
ezgh objects buckets lifecycle get my-bucket
ezgh objects buckets lifecycle delete my-bucket
```

| Field | Value |
| --- | --- |
| `id` | The rule's ID. Optional |
| `status` | `enabled` or `disabled` |
| `prefix` | Optional. Left out, the whole bucket |
| `expirationDays` | Delete objects after this many days |
| `expirationDate` | Delete objects on this date, such as `2027-01-01T00:00:00Z`. Not with `expirationDays` |
| `noncurrentVersionExpirationDays` | Delete noncurrent versions this many days after a newer version replaces them |
| `expiredObjectDeleteMarker` | `true` removes expired delete markers. Not with `expirationDays` or `expirationDate` |
| `abortIncompleteMultipartUploadDays` | Abort unfinished multipart uploads after this many days, 1 to 7 |

`get --output json` prints the rules as `put --file` takes them. `put` with a rule that deletes
objects, and `delete`, ask first on a terminal; `--yes` confirms otherwise. See the
[command reference](/cli/reference/objects-buckets-lifecycle).

## API

[GetBucketLifecycle](/objects-api/GetBucketLifecycle/) and
[PutBucketLifecycle](/objects-api/PutBucketLifecycle/) in the Object Storage API read and
replace the same rules, in the JSON the CLI takes. An empty list removes every rule.

## Not supported

A configuration with any of these is refused with `NotImplemented`, and the message names the
element:

| Element | In S3 |
| --- | --- |
| Transitions | `Transition`, `NoncurrentVersionTransition` |
| Keeping a number of noncurrent versions | `NewerNoncurrentVersions` |
| Tag filters | `Tag` |
| Object-size filters | `ObjectSizeGreaterThan`, `ObjectSizeLessThan` |

## Permissions

| To | You need |
| --- | --- |
| View rules | `objects.buckets.get` |
| Set rules | `objects.buckets.update` and `objects.objects.delete` |
| Remove every rule | `objects.buckets.update` |

These apply to the console, the CLI, the API and S3 requests alike. See
[Permissions](/object-storage/access-keys#permissions).

## Trails

Trails records changes to a bucket's lifecycle rules. It doesn't record the objects a rule deletes.

Source: https://docs.ezghcloud.com/object-storage/lifecycle-rules/index.mdx
