Home > Mobile >  How do I create an S3 lifecycle policy that moves everything to intelligent tiering and maintains a
How do I create an S3 lifecycle policy that moves everything to intelligent tiering and maintains a

Time:04-29

I am trying to figure out the exact S3 bucket lifecycle rules I need for my use case. I think I've got it right but my testing has been inconclusive - from AWS's docs it looks like there is an undefined lag between when a rule should have been applied and when it actually is. All that they guarantee is that the billing will reflect the defined rules. I also find the wording in their docs and in the S3 UI confusing and ambiguous.

The configuration I want is this:

  • all files and versions to be placed in Intelligent Tiering ASAP
  • in addition to the current version, maintain ONE previous version
  • ... but delete that previous version after 90 days

I'm setting policies via the ruby SDK as follows:

  s3.put_bucket_lifecycle_configuration(
    bucket: 'my-awesome-bucket',
    lifecycle_configuration: {
      rules: [
        {
          id: 'my-awesome-policy',
          prefix: '',
          status: 'Enabled',
          transitions: [
            {
              storage_class: 'INTELLIGENT_TIERING',
              days: 0
            }
          ],
          noncurrent_version_transitions: [
            {
              storage_class: 'INTELLIGENT_TIERING',
              noncurrent_days: 0
            }
          ],
          noncurrent_version_expiration: {
            noncurrent_days: 90
          } 
        } 
      ] 
    }
  )

Is this correct? I'm aware that there are similar questions out there, but the options here have subtly changed in recent years and I want to be absolutely sure I've got it right.

CodePudding user response:

When designing your s3 lifecycle policies, you have keep in mind the following:

  • Minimum Days for Transition from S3 Standard or S3 Standard-IA to S3 Standard-IA or S3 One Zone-IA

This means that before you can move any of your objects, you must store them at least 30 days in the S3 Standard storage class.

  • The 0 days rule is not as ASAP as you might think.

This rule means that the objects are eligible for transition at midnight UTC following creation and the minimum storage time (see the previous point).

  • S3 Lifecycle configurations supports keeping 1 to 100 versions of any object.

A versioning-enabled bucket has one current version and zero or more noncurrent versions for each object. So, in your case, you'd use something like this:

<LifecycleConfiguration>
    <Rule>
        ...
        <NoncurrentVersionExpiration>     
            <NewerNoncurrentVersions>1</NewerNoncurrentVersions>
            <NoncurrentDays>90</NoncurrentDays>    
        </NoncurrentVersionExpiration>
    </Rule>
</LifecycleConfiguration>

Hope this helps you understand the s3 lifecycle policy rules and validate yours, taking into the consideration the constraints.

  • Related