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
preguntada hace 7 meses1738 visualizaciones
2 Respuestas
0
Respuesta aceptada

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 hace 7 meses
profile picture
EXPERTO
revisado hace 7 meses
0

Nice - I like the queue solution!

dmb0058
respondido hace 7 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas