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달 전1724회 조회
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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠