python - 使用 Python 从公共(public) AWS S3 下载文件/文件夹,无需凭证

标签 python amazon-web-services amazon-s3

我已经打开了对 S3 存储桶的公共(public)访问权限,我需要使用 python 从存储桶中下载带有文件的文件/文件夹。诀窍是我不想提供凭据(boto3 显然需要)。甚至可能吗?

最佳答案

您可以使用获取对象 来自 S3 REST API,连同 请求 Python 中的库。如果您向匿名用户授予 READ 访问权限,则可以在不使用授权 header 的情况下返回对象。

此类 S3 REST 调用的示例:

> GET /example-object HTTP/1.1
> Host: example-bucket.s3.<Region>.amazonaws.com    

Python(粗略示例):
import requests
url = '/example-object'
headers = {'Host': 'example-bucket.s3.<Region>.amazonaws.com'}
r = requests.get(url, headers=headers)

Requests

GetObject

关于python - 使用 Python 从公共(public) AWS S3 下载文件/文件夹,无需凭证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62086013/

相关文章:

C# MVC/API - 从 Amazon S3 为我的 API 调用返回图像

amazon-web-services - 使用 Serverless 和 Node js 从 S3 存储桶获取文件

python - 如何在 python 中使用 SQLAlchemy SQL-builder 执行 UPDATE 查询?

python - SQLAlchemy:按多态子类过滤现有查询(相当于 `.of_type()` 但针对 `session.query()` )

python - 如何修复 Python 缩进

database - 在多个区域扩展身份服务

amazon-web-services - YAML_FILE_ERROR 消息 : Wrong number of container tags, 应为 1

python - 使用 boto 的 S3 对象过期

amazon-web-services - 无法选择 S3 文件夹作为 AWS 上 CodePipeline 的源

python - 如何使用 Python 将按列嵌套的 CSV 文件转换为嵌套字典?