---
title: "Managing Object Lifecycle in S3 | Hostman Docs"
description: "Learn how to manage object Lifecycle in S3 storage with Hostman dashboard and AWS CLI"
---

> For the complete documentation index for AI agents, see [llms.txt](https://hostman.com/llms.txt).

When using [S3](https://hostman.com/products/s3-storage/), you may need to manage the lifecycle of objects to optimize resource usage and prevent storage overflow. To achieve this, you can configure lifecycle rules, which automatically delete objects after a specified number of days.

Here’s how to set up lifecycle rules for objects in an S3 bucket using the Hostman dashboard and the AWS CLI.

## Via the Dashboard

### Creating Rules

To create lifecycle rules:

1.  Go to the **S3 Storage** section and click on the bucket.
2.  In the **Settings** tab, click **Change** next to **Lifecycle**.

![Cdf1f9d8 689b 4713 Aec4 5fb1730689af](https://content.hostman.com/assets/b1bbf7a4-a554-4b3d-b13f-590b53146f1b.png?width=1547&height=1141)

3.  Click **Add rule**.
4.  Set up the parameters:

-   -   **Object prefix**. For example, if you set the prefix `logs/`, the rule will only apply to objects in the `logs` “folder.”
    -   **Action**. Choose what should happen to the objects and after how many days the action should be applied. Three options are available:
        -   **Delete any**: applies to any object in the bucket.
        -   **Delete non-current**: applies to old versions of objects (relevant if object versioning is enabled).
        -   **Abort incomplete upload**: automatically removes unfinished multipart uploads.

5.  Click **Save**.
    

![23ad3920 2560 4904 9d02 Ecb1da936265](https://content.hostman.com/assets/1edc4599-c528-40d0-85c1-675439e18965.png?width=1689&height=869)

### Managing Existing Rules

To view and manage all existing lifecycle rules:

1.  Go to the **S3 Storage** section and click on the bucket.
2.  In the **Settings** tab, click **Change** next to **Lifecycle**.

The window will display all existing rules, including those added through external tools such as the AWS CLI.

Here, you can:

-   **Delete a rule** by clicking the trash bin icon.
-   **Temporarily disable a rule** by toggling the switch.
-   **Edit a rule** by clicking on it to open the edit window.

![Fee1d050 Ea32 4ab6 B6e9 66f9996f2cb0](https://content.hostman.com/assets/da61e346-8195-4868-9b8c-1bb14a48b97d.png?width=1538&height=749)

## Via AWS CLI

### Creating a Lifecycle Rule File

To set up automatic deletion of files after a certain period, create a configuration file for the lifecycle rules. For example, if you want to store files in the logs folder for only **one day**, create a file named `lifecycle.json` with the following content:

```shell
{
  "Rules": [
    {
      "Status": "Enabled",
      "Filter": {"Prefix": "logs/"},
      "Expiration": {"Days": 1}
    }
  ]
}
```

-   `Prefix`: Specifies the folder (or prefix) to which the rule will apply. In this example, files in the `logs/` folder will be automatically deleted after one day.
    
-   `Expiration`: Defines the retention period in days. Here, files are deleted one day after upload.
    

### Adding Multiple Rules

You can add multiple rules for different folders or files. For instance, if you have another folder, `logs2`, where files should be stored for **two days**, simply add an additional rule:

```shell
{
  "Rules": [
    {
      "Status": "Enabled",
      "Filter": {"Prefix": "logs/"},
      "Expiration": {"Days": 1}
    },
    {
      "Status": "Enabled",
      "Filter": {"Prefix": "logs2/"},
      "Expiration": {"Days": 2}
    }
  ]
}
```

With this configuration:

-   Files in the `logs/` folder will be retained for one day.
-   Files in the `logs2/` folder will be retained for two days.

### Uploading Lifecycle Rules to a Bucket

After creating the lifecycle rule file, upload it to your S3 bucket using the following command:

```shell
aws s3api put-bucket-lifecycle-configuration --bucket <bucket_name> --lifecycle-configuration file://lifecycle.json --endpoint-url https://s3.hmstorage.net
```

This command applies the specified rules to your bucket, and files will be automatically deleted after the defined period.

### Verifying Lifecycle Rules

To ensure that the lifecycle rules were successfully applied, run the following command:

```shell
aws s3api get-bucket-lifecycle-configuration --bucket <bucket_name> --endpoint-url https://s3.hmstorage.net
```

This will display the current lifecycle rules configured for your bucket.

### Removing Lifecycle Rules

If you need to delete all existing lifecycle rules for a bucket, execute the following command:

```shell
aws s3api delete-bucket-lifecycle --bucket <bucket_name> --endpoint-url https://s3.hmstorage.net
```

This command removes all lifecycle rules, and files will no longer be automatically deleted.
