最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Best practice to handle aws s3 presigned URL expiration date - Stack Overflow

programmeradmin1浏览0评论

I'm saving images to my s3 bucket, generate a presigned URL and save that as a field in my model schema. When my frontend retrieves the model objects from the backend it uses that URL to retrieve the images.

The max expiration date you can set with v4 is 7 days. So what is the best practice to handle the "refreshing" of those URLs?

Things I thought about:

  • Having a cron job in my backend that checks every e.g. every 24 hours if I have any URLs going invalid within the next 24h and generate a new one in case.
  • Checking it everytime I receive a GET request and re-generate if it's invalid
  • Not checking at all on the backend, and just try to the hit the URL on the frontend and if I get a 403 to then request the re-generation from the backend. I don't like this idea that much though as I couldn't simply use "/> but have to wrap it in some other logic.

I'm saving images to my s3 bucket, generate a presigned URL and save that as a field in my model schema. When my frontend retrieves the model objects from the backend it uses that URL to retrieve the images.

The max expiration date you can set with v4 is 7 days. So what is the best practice to handle the "refreshing" of those URLs?

Things I thought about:

  • Having a cron job in my backend that checks every e.g. every 24 hours if I have any URLs going invalid within the next 24h and generate a new one in case.
  • Checking it everytime I receive a GET request and re-generate if it's invalid
  • Not checking at all on the backend, and just try to the hit the URL on the frontend and if I get a 403 to then request the re-generation from the backend. I don't like this idea that much though as I couldn't simply use "/> but have to wrap it in some other logic.
Share Improve this question edited Nov 28, 2019 at 3:46 John Rotenstein 270k28 gold badges446 silver badges530 bronze badges asked Nov 27, 2019 at 22:42 phoebusphoebus 1,3291 gold badge17 silver badges42 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

The best practice is do not store pre-signed URLs.

Instead, generate them on-the-fly when they are required. They only take a couple of lines of code to generate, and generation does not involve a call to AWS.

So, whenever the app needs to reference a pre-signed URL, immediately generate and use it. There will be no need to worry about expiration times.

发布评论

评论列表(0)

  1. 暂无评论