How to apply the lifecycle policy with AWS CLI
This section follows the same step in the previous section, but the difference is to use AWS CLI to apply a lifecycle rule. The advantage is that it is able to manage a lifecycle policy file in JSON format.
Getting ready
You do not have to request permissions to configure lifecycle policy over your bucket. All you need to do is:
Sign up on AWS and be able to access S3 with your IAM credentials
Enable Server Access Logging to your bucket
How to do it…
To enable the lifecycle of objects using AWS CLI, you need to create a lifecycle policy in the JSON format and use the aws s3api
subcommand to configure the lifecycle policy for you bucket. We are configuring the same policy used in the previous section. Now, let's start to create the policy with AWS CLI:
Create a lifecycle policy file:
$ policy=lifecycle_policy.json $ cat> ${policy} <<EOF { "Rules": [ { "Status": "Enabled", "Prefix": "logs/", "Expiration...