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
已提問 7 個月前檢視次數 1727 次
2 個答案
0
已接受的答案

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
已回答 7 個月前
profile picture
專家
已審閱 7 個月前
0

Nice - I like the queue solution!

dmb0058
已回答 7 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南