amazon-web-servicesamazon-s3aws-sdk

How to create/cache presigned URLs for photo module?


I want to integrate a photo album feature to my app where users can upload and share albums with others. Now I upload these photos to an S3 bucket. I'm asking myself what's the best approach to grant access to these images is. I thought about these three options:

  1. Deliver images through my app ta access them securely
  2. Create (longer term) presigned URLs and cache them in a DB or Cache until expiration
  3. Create the presigned URLs for all images on every request

1st idea would cause a high unnecessary load on my application. 2nd would mean I have to implement a logic to request new presigned URL if on expired and 3rd would cause I higher response time due to the creation of this presigned URLs againest the AWS-API (haven't checked out the limitations yet).

What is your suggestions?


Solution

  • Use #3.

    Pre-signed URLs can be created in a couple of lines of code and do not require a call back to AWS. Pre-signed URLs are just hashed signatures created with an HMAC function.

    When a user navigates to a page of their photos, you can show the thumbnails by including pre-signed URLs in the HTML <img> tags. You can also provide a pre-signed URL that links to the full-size version if they click on a photo.