ansible-collections / community.aws

Ansible Collection for Community AWS
GNU General Public License v3.0
189 stars 398 forks source link

s3_lifecycle - Add size thresholds #861

Open mdavis-xyz opened 2 years ago

mdavis-xyz commented 2 years ago

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

alinabuzachis commented 2 years ago

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

mdavis-xyz commented 2 years ago

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.)