Skip to content

Instantly share code, notes, and snippets.

@tanmay-bhat
Created July 20, 2022 07:02
Show Gist options
  • Save tanmay-bhat/341c0284b57e644b7eb8a0f49a606f82 to your computer and use it in GitHub Desktop.
Save tanmay-bhat/341c0284b57e644b7eb8a0f49a606f82 to your computer and use it in GitHub Desktop.
AWS S3 lifecycle policy to delete all files in bucket older than 60 days via CLI
  • Create a file called lifecycle.json and append the below into it :
{
    "Rules": [
        {
            "ID": "Delete files older than 60 days",
            "Prefix": "",
            "Status": "Enabled",
            "Expiration": 
                {
                    "Days": 60
                }
        }

    ]
}
  • Run the below command to set the policy on the existing bucket :
aws s3api put-bucket-lifecycle-configuration --bucket <bucket-name> --lifecycle-configuration  file://lifecycle.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment