Does anyone know how to speed up presigning S3 URLs?
I'm working on a toy project where users upload content, and I noticed that it takes forever to load an image, and the bottleneck seems to be in creating a presigned URL on my machine. There could be other faults in my code or optimizations I could make, but some info:
- I'm testing this on an M2 Macbook Air
- I have a trpc procedure which generates the presigned URL and returns it to the client
- I'm using
getSignedUrl
from @aws-sdk/s3-request-presigner
- It takes over half a second to run getSignedUrl
based on my tests
Is there some pitfall I'm falling into? Is there a better alternative?
inb4 use UploadThing, I'm using this project to learn, otherwise I'd be happy to.Solution:Jump to solution
This isnt exactly an answer. But I do similar things for my project where I store user uploaded images on S3. I generate keys which last for a week and cache the urls in my DB. Doesn't eliminate the first slow-down, but eliminates the vast majority. And if I really wanted to I could run a cron to regenerate all urls every ~6 days. This probably doesnt scale too amazingly, but I wouldnt be using S3 for this purpose in that case anyways
2 Replies
Solution
This isnt exactly an answer. But I do similar things for my project where I store user uploaded images on S3. I generate keys which last for a week and cache the urls in my DB. Doesn't eliminate the first slow-down, but eliminates the vast majority. And if I really wanted to I could run a cron to regenerate all urls every ~6 days. This probably doesnt scale too amazingly, but I wouldnt be using S3 for this purpose in that case anyways
Thanks for the answer! I like this solution. I'm gonna try this, and also I'll see what I can do about the first slow-down. I'm thinking of generating the URL on upload, but we'll see how that goes.