community.aws icon indicating copy to clipboard operation
community.aws copied to clipboard

s3_lifecycle - Add size thresholds

Open mdavis-xyz opened this issue 2 years ago • 2 comments

Summary

STANDARD_IA and GLACIER classes in S3 include an overhead for access history data. For small files the overhead can be larger than the file itself, so you end up paying more to store small files in these supposedly cheaper classes.

The solution is to add a minimum size filter to the lifecycle config. The API supports this. The s3_lifecycle ansible module does not yet support these. We should add a min size filter (and also max size filter).

Issue Type

Feature Idea

Component Name

s3_lifecycle

Additional Information

In the boto3 call, ObjectSizeGreaterThan and ObjectSizeLessThan are optional fields which go next to Prefix under Filter. They are the number of bytes (not kB).

I propose this usage:

- name: Configure a lifecycle rule on a bucket to expire (delete) items with a prefix of /logs/ after 30 days
  community.aws.s3_lifecycle:
    name: mybucket
    expiration_days: 30
    prefix: logs/
    object_size_greater_than: 123
    object_size_less_than: 123
    status: enabled
    state: present

Code of Conduct

  • [X] I agree to follow the Ansible Code of Conduct

mdavis-xyz avatar Jan 13 '22 00:01 mdavis-xyz

@mdavis-xyz Thank you for this feature idea. Would you be willing to work on it and open a pull request?

alinabuzachis avatar Jan 13 '22 09:01 alinabuzachis

I just found out that Lifecycles actually already have a minimum size filter for these transitions.

link to docs

Objects smaller than 128 KB – For the following transitions, Amazon S3 does not transition objects that are smaller than 128 KB:

From the S3 Standard or S3 Standard-IA storage classes to S3 Intelligent-Tiering or S3 Glacier Instant Retrieval.

From the S3 Standard storage class to S3 Standard-IA or S3 One Zone-IA.

Therefore I don't need this new Ansible functionality for my use case. So I probably won't write this until much later this year when I get some spare time (and after writing other PRs I more urgently need.)

mdavis-xyz avatar Jan 13 '22 22:01 mdavis-xyz