• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. User Guide (S3cmd)
  4. Operation Guide
  5. Object Management
  6. Configuring an Expiration Rule for an Object

Configuring an Expiration Rule for an Object

Expired objects are added to the deletion queue on OBS for asynchronous deletion. You will no longer be charged for storage fees once objects expire. For this reason, you can configure expiration rules for objects to save costs.

NOTE:

Similar to lifecycle rules of buckets, expiration rules of objects can be configured to delete specific objects. A new rule overwrites the exiting one. For example, if you configure a bucket lifecycle rule first and then configure an object expiration rule, the object expiration rule prevails for both the bucket and objects.

Procedure

  1. Open the command line tool.
  2. Run the following command to configure an object expiration rule:

    s3cmd expire --expiry-days=EXPIRY_DAYS --expiry-prefix=EXPIRY_PREFIX s3://my-bucket

    NOTE:
    • --expiry-days=EXPIRY_DAYS is mandatory, and indicates the number of days when objects expire after their creation. EXPIRY_DAYS specifies the number of days.
    • --expiry-prefix=EXPIRY_PREFIX is optional, and indicates the objects with specific prefixes. EXPIRY_PREFIX is the specific prefix. If this parameter is not used, it indicates all objects in a bucket.
    • my-bucket is the specific bucket where objects reside.

    After the command is successfully executed, information similar to the following is displayed in the command output:

    Bucket 's3://my-bucket/': expiration configuration is set.

  3. (Optional) Run the following command to view an object expiration rule:

    s3cmd info s3://my-bucket

Follow-up Procedure

You can delete an object expiration rule as follows if necessary:

  1. Open the command line tool.
  2. Run the following command to delete an object expiration rule:

    s3cmd expire s3://my-bucket

    If information similar to the following is displayed in the command output, it indicates that the expiration rule is successfully deleted:

    Bucket 's3://my-bucket/':expiration configuration is deleted.

  3. (Optional) Run the following command to view an object expiration rule:

    s3cmd info s3://my-bucket