• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

AWS CLI S3 Lifecycle

December 9, 2018

Here’s how to add a lifecycle management to S3 buckets via the CLI. In this example, expiration is set to 7 days. S3 will auto delete expired objects.

$aws s3api put-bucket-lifecycle-configuration \
--bucket bucketname --lifecycle-configuration file://lifecycle.json

$aws s3api put-bucket-lifecycle-configuration \ --bucket bucketname --lifecycle-configuration file://lifecycle.json

The lifecycle is defined in this JSON file.

{
  "Rules": [ 
    {
       "ID": "Expires in 7 DAYS", 
       "Prefix": "", 
       "Status": "Enabled", 
       "Expiration": { 
         "Days": 7
         }
    } 
  ] 
}

{ "Rules": [ { "ID": "Expires in 7 DAYS", "Prefix": "", "Status": "Enabled", "Expiration": { "Days": 7 } } ] }

Filed Under: Cloud, Linux Tagged With: aws cli, lifecycle, s3

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023