It seems like signed URLs will always have a default expiration: https://github.com/aws/aws-sdk-js/blob/fd5fb93f8ffa4ce96933fe0418a95218b526c637/lib/services/s3.js#L371.
Is there some other way to disable expiration?
If not, is there any effective upper limit on the expiration interval? i.e. could I set it to, say, 5 years?
@wearhere if you are using the default 's3' signature version, you can set the params.Expires to 200 years or any other value.
If you are using signature version 4 then the maximum expiry time on presigned URLs is one week.
Hope this helps clarify things!
Ok thanks!
Isn't the better solution to make the object public and link to it like normal? The PHP SDK has a getObjectUrl which essentially just build the URL for you without the signature requirement.
Oh! That would be great. All the examples I had seen used getSignedUrl.
@AdityaManohar is it possible to get a public link like @dmyers suggests using the JS SDK? I don't see getObjectUrl in the JS reference.
I managed to hack it by looking at the private APIs in the JS internals like this:
var client = new AWS.S3();
var req = new AWS.Request(client, 'getObject', {Key: key, Bucket: bucket});
client.populateURI(req);
var fullUrl = req.httpRequest.endpoint.protocol + "//" + req.httpRequest.endpoint.host + '/' + path;
The PHP SDK mainly looks at the final URL built from the request package Guzzle, I couldn't figure out how to do it in Node myself and that was the best solution other than hardcoding any hostnames as I wanted to have the same logic as the PHP version I used in the past.
The reason I prefer it over the signed url is that it doesn't perform a real HTTP request, it simply gets the URL for say linking in an image tag in HTML or storing in your database.
Awesome thanks @dmyers!
Hmm @dmyers that didn't work for me. That generated a URL with the format https://{bucket}.s3-{region}.amazonaws.com/{key}, whereas what is required is https://s3-{region}.amazonaws.com/{bucket}/{key}. Not sure why there is a difference...
@AdityaManohar but according to this, the default signature is being V4 now. Does it mean longer-than-7-day expiration time is not possible? I use default signature version and pass 7,776,000 (90 days) to Expire but I get The provided token has expired error just after 4 days.
Are there any plans to add this feature to aws-sdk-js? Something similar to what is available already in e.g. aws-sdk-ruby would suffice. Currently we need to resort to workarounds like handcrafting the urls or using 3rd party packages.
Yep, following this. I need the same feature.
This thread has been rolling since 2015. So far we got hacks to make it work. I doubt it will get any implementation towards it. Which makes the function kinda useless in a sense if you can't really use it past short time expiration time.
Why only one week? This value should depends on busines rules of each application...
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Most helpful comment
Why only one week? This value should depends on busines rules of each application...