How to Omit a sub folder from the Lifecycle Policy

0

I want to omit an entire sub folder from a lifecycle policy. The folder which we want to omit from the lifecycle policy is present inside the folder where we want to apply the lifecycle policy along with the rest of the data. It is not possible to move the folder outside the main folder also files may be added inside the folder in future which should also not get affected using the lifecycle policy. Is there any way we can achieve this. Note - I cannot use the object tags here because object tags can only be used on all the objects inside a folder but files will be added to the folder on a daily basis so we need to omit the whole folder rather than using the object tags for specific objects.

asked a year ago461 views
1 Answer
0

Unfortunately you're going to have to create rules for all folders (or actually prefixes, to use to right term) except the one you want to exclude. Regular expressions can't be used to create a rule like "all prefixes except /foo/bar".

if you can't use tags then another way round this is that if your rule is going to be "apply to everything over X days old" then once a day (or week, or month) run a job to basically do the same as the Linux touch command and change the last modified date everything in the folder so that it never falls within scope of the rule.

$ aws s3 ls s3://my-practice-bucket/downloads.zip
2023-05-11 11:42:15     105593 downloads.zip
$ aws s3 cp --metadata '{"touched":"now"}' s3://my-practice-bucket/downloads.zip s3://my-practice-bucket/downloads.zip
copy: s3://my-practice-bucket/downloads.zip to s3://my-practice-bucket/downloads.zip
$ aws s3 ls s3://my-practice-bucket/downloads.zip
2023-06-06 13:16:53     105593 downloads.zip
$

(NB I'm not sure if this will work if versioning is enabled on the bucket).

profile picture
EXPERT
Steve_M
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions