How to set an expiration rule for an S3 object (not bucket)?

1

I have an S3 bucket containing a number of objects that fall into three classes. They fall into three classes:

  1. objects that should expire in 15 minutes,
  2. objects that should expire after a day and
  3. objects that should never expire automatically.

I would like to use native AWS functionality to do this, rather than running a separate process to scan the bucket and delete objects (yuck).

I really want to avoid having three buckets, with a bucket-level lifecycle rule on each with different expiration periods as it's far easier in my application to set the expiration at object creation time, if this is actually possible.

I think I can do this with three tags and a lifecycle configuration on the bucket, but this seems to have a granularity of 1 day, i.e. I can't delete in less than a day. Setting the expiry date per object would fix this but I can't see any way to do this.

Any ideas welcome :)

David

dmb0058
feita há 7 meses1725 visualizações
2 Respostas
0
Resposta aceita

Unfortunately, S3 lifecycle policy only supports expiration by days, so if you want to expire your objects in minutes, you need to develop your own solution.

As a possible solution, after you upload an S3 object that you want to expire in 15 minutes, you push its bucket and key info into an SQS queue. You can delay the message visibility for 15 minutes so that your queue processing function can "delay" the deletion for 15 minutes after the object was upload.

profile picture
HS
respondido há 7 meses
profile picture
ESPECIALISTA
avaliado há 7 meses
0

Nice - I like the queue solution!

dmb0058
respondido há 7 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas