Issue
I am currently using the following to create a pre-signed url for a bucket resource:
bucket_name = ...
key = ...
s3_client = ...
s3_client.generate_presigned_url(
ClientMethod="get_object",
Params={
"Bucket": bucket_name,
"Key": key
},
ExpiresIn=100
)
This works fine. However, I was wondering if it was possible to generate pre-signed urls for multiple keys in one request? Or is it required to make one request for each key? I didn't find anything useful in the docs regarding this topic. I'm looking for something like this:
bucket_name = ...
keys = [...]
s3_client = ...
# Returns an array of pre-signed urls, in the same order as `keys`
s3_client.generate_presigned_url(
ClientMethod="get_object",
Params={
"Bucket": bucket_name,
"Keys": keys
},
ExpiresIn=100
)
Solution
Generating presigned URLs is actually done locally, without requiring a call to AWS. This is because all necessary information (Bucket, Key, Secret Key) is known locally and can generate the signature.
Therefore, feel free to call that function repeatedly since there is no network/service overhead.
In general, there should be no need to bulk-generate URLs. Instead, whenever your application wishes to reference a resource (eg an image on an HTML page), it can quickly call the generate_presigned_url()
function with an appropriate timeout.
Answered By - John Rotenstein
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.