批量生成预签名URL boto3 [英] Bulk Generate Pre-Signed URLs boto3

查看:90
本文介绍了批量生成预签名URL boto3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用以下内容为存储桶资源创建预签名的网址:

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
)

这很好.但是,我想知道是否可以在一个请求中为多个键生成预签名的url?还是需要为每个密钥提出一个请求?在该主题的文档中,我没有发现任何有用的信息.我正在寻找这样的东西:

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
)

推荐答案

生成预签名URL实际上是在本地完成的,不需要调用AWS.这是因为所有必需的信息(桶,密钥,秘密密钥)在本地都是已知的,并且可以生成签名.

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.

通常,不需要大量生成URL.相反,只要您的应用程序希望引用资源(例如HTML页面上的图像),它就可以在适当的超时时间内快速调用 generate_presigned_url()函数.

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.

这篇关于批量生成预签名URL boto3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆