

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 建立和管理物件生命週期組態 AWS CLI
<a name="working-s3-snow-buckets-lifecycle-s3-snow"></a>

您可以使用 Amazon S3 生命週期來最佳化 Snowball Edge 上 Amazon S3 相容儲存的儲存容量。您可以建立生命週期規則，在物件老化或取代為較新的版本時使這些物件過期。您可以建立、啟用、停用或刪除生命週期規則。如需 Amazon S3 生命週期的詳細資訊，請參閱[管理您的儲存生命週期](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html)。

**注意**  
建立儲存貯體 AWS 帳戶 的 擁有它，是唯一可以建立、啟用、停用或刪除生命週期規則的 。

若要使用 AWS Command Line Interface (AWS CLI) 在 Snowball Edge 儲存貯體上建立和管理 Amazon S3 相容儲存體的生命週期組態，請參閱下列範例。

## 在 Snowball Edge 儲存貯體上放置生命週期組態
<a name="put-s3-snow-example"></a>

下列 AWS CLI 範例會在 Snowball Edge 儲存貯體上放置生命週期組態政策。此政策指定具有標記字首 (*myprefix*) 和標籤的所有物件會在 10 天後過期。若要使用此範例，請以您自己的資訊取代每個 使用者輸入預留位置。

首先，將生命週期組態政策儲存到 JSON 檔案。在此範例中，檔案名為 **lifecycle-example.json**。

```
{
    "Rules": [{
        "ID": "id-1",
        "Filter": {
            "And": {
                "Prefix": "myprefix",
                "Tags": [{
                        "Value": "mytagvalue1",
                        "Key": "mytagkey1"
                    },
                    {
                        "Value": "mytagvalue2",
                        "Key": "mytagkey2"
                    }
                ]
            }
        },
        "Status": "Enabled",
        "Expiration": {
            "Days": 10
        }
    }]
}
```

儲存檔案之後，請提交 JSON 檔案做為 `put-bucket-lifecycle-configuration`命令的一部分。若要使用此命令，請以您自己的資訊取代每個 使用者輸入預留位置。

**Example `put-bucket-lifecycle` 命令的**  

```
aws s3api put-bucket-lifecycle-configuration --bucket example-snow-bucket  \\
    --lifecycle-configuration file://lifecycle-example.json --endpoint-url https://s3api-endpoint-ip --profile your-profile
```
如需此命令的詳細資訊，請參閱《 AWS CLI 命令參考》中的 [put-bucket-lifecycle-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/put-bucket-lifecycle-configuration.html)。

```
aws s3control put-bucket-lifecycle-configuration --bucket example-snow-bucket \\
    --lifecycle-configuration file://lifecycle-example.json \\
    --endpoint-url https://s3ctrlapi-endpoint-ip --profile your-profile
```
如需此命令的詳細資訊，請參閱《 AWS CLI 命令參考》中的 [put-bucket-lifecycle-configuration](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3control/put-bucket-lifecycle-configuration.html)。