mike
mike

Reputation: 1663

On AWS S3, can I exclude a file from lifecycle rule

I have a bucket that has a short lifecycle rule, everything older than 7 days gets deleted. The files that are added have dynamically generated names.

There is one file in the bucket that I would like to exclude from this rule, is there a way to exclude this file from the rule so it is never deleted?

Upvotes: 12

Views: 14470

Answers (3)

Jonas Barcat
Jonas Barcat

Reputation: 21

Hey a bit late but I found an alternative solution that may work.

You can implement Object Lock S3 property. When you turn on Object Lock for a bucket, the bucket can store protected objects, it means that these specific objects can't be deleted from the bucket for a specific period of time.

Object Lock seems to have precedence above Lifecycle.

Here is the reference: AWS Object Lock Documentation

Upvotes: 2

AndreKR
AndreKR

Reputation: 33678

If the file is small enough so that it doesn't matter to pay for Glacier and S3 storage, you could also initiate a restore and set Days to a very high number.

Upvotes: 1

Michael - sqlbot
Michael - sqlbot

Reputation: 179124

There is not a way to exclude objects from rules that match them. Most likely, you will need to rearrange your objects using prefixes that meet your needs.

There is a hack... which would involve copying the file into itself frequently enough that it never ages enough to match the rule, but that is obviously delicate. The S3 PUT+Copy operation does allow an object to be copied on top of itself non-destructively without downloading and re-uploading, and this would reset the expiration timer.

But most likely a better solution is to prefix your random filenames with a few static characters. The S3 partition splitting implementation (the way S3 handles bucket capacity scaling) can apparently work just as well with with a static prefix (e.g. images/) followed by random characters as it can with entirely random keys.

Upvotes: 10

Related Questions