Boto3 - 如何通过代理连接到 S3?
Boto3 - how to connect to S3 via proxy?
我在 http://127.0.0.1:4569 上使用模拟 S3 服务器 运行 的容器(无需授权或凭据)
我正在尝试使用 python 和 boto3
简单地连接并打印所有存储桶名称的列表
这是我的 docker-撰写:
s3:
image: andrewgaul/s3proxy
environment:
S3PROXY_AUTHORIZATION: none
hostname: s3
ports:
- 4569:80
volumes:
- ./data/s3:/data
这是我的代码:
s3 = boto3.resource('s3', endpoint_url='http://127.0.0.1:4569')
for bucket in s3.buckets.all():
print(bucket.name)enter code here
这是我收到的错误消息:
botocore.exceptions.NoCredentialsError: Unable to locate credentials
我试过这个解决方案 =>
但还是不行,我不明白我做错了什么
首先,boto3 总是尝试使用 AWS API 密钥与 S3 服务器握手。即使您的模拟服务器不需要密码,您仍然需要在 .aws/credentials 或程序中指定它们。例如
[default]
aws_access_key_id = x
aws_secret_access_key = x
硬编码虚拟访问密钥示例
import boto3
session = boto3.session(
aws_access_key_id = 'x',
aws_secret_access_key = 'x')
s3 = session.resource('s3', endpoint_url='http://127.0.0.1:4569')
其次,我不知道你的"s3 simulation container"实现的协议有多可靠,是什么样的协议。为了让生活更轻松,我总是建议任何想要模拟 S3 负载测试或使用任何东西的人 fake-s3
我在 http://127.0.0.1:4569 上使用模拟 S3 服务器 运行 的容器(无需授权或凭据)
我正在尝试使用 python 和 boto3
简单地连接并打印所有存储桶名称的列表这是我的 docker-撰写:
s3:
image: andrewgaul/s3proxy
environment:
S3PROXY_AUTHORIZATION: none
hostname: s3
ports:
- 4569:80
volumes:
- ./data/s3:/data
这是我的代码:
s3 = boto3.resource('s3', endpoint_url='http://127.0.0.1:4569')
for bucket in s3.buckets.all():
print(bucket.name)enter code here
这是我收到的错误消息:
botocore.exceptions.NoCredentialsError: Unable to locate credentials
我试过这个解决方案 =>
但还是不行,我不明白我做错了什么
首先,boto3 总是尝试使用 AWS API 密钥与 S3 服务器握手。即使您的模拟服务器不需要密码,您仍然需要在 .aws/credentials 或程序中指定它们。例如
[default]
aws_access_key_id = x
aws_secret_access_key = x
硬编码虚拟访问密钥示例
import boto3
session = boto3.session(
aws_access_key_id = 'x',
aws_secret_access_key = 'x')
s3 = session.resource('s3', endpoint_url='http://127.0.0.1:4569')
其次,我不知道你的"s3 simulation container"实现的协议有多可靠,是什么样的协议。为了让生活更轻松,我总是建议任何想要模拟 S3 负载测试或使用任何东西的人 fake-s3