当我想使用 boto3 访问我的 S3 存储桶时,我只需这样做:
import boto3
s3_client = boto3.client('s3')
response = s3_client.list_objects_v2(
Bucket='[bucket name]',
Prefix='[prefix]'
)
但是,如果我需要访问另一个服务器中的另一个 S3 存储桶(不是我的,而是来自客户端)Server = bucket/prefix.s3.amazonaws.com)
怎么办?
此解决方案似乎不起作用:
import boto3
s3_client = boto3.client('s3', aws_access_key_id='[other access key]',
aws_secret_access_key='[other secret key]')
response = s3_client.list_objects_v2(
Bucket='[bucket name]',
Prefix='[prefix]'
)
我可以使用 Cyberduck 毫无问题地访问 S3(指定服务器、访问密钥 ID 和密钥 ID),但是在脚本上我得到access denied
.
我尝试指定添加到 boto3.client 的任何其他区域region_name='[region]'
,但除了拒绝访问之外,有时我遇到的另一个错误是An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.
这没有多大意义,因为它与 Cyberduck 和 bash 脚本中使用的相同,格式如下:
SOURCE_FOLDER=s3://bucket/prefix
SEC_KEY=[other secret key]
ACC_KEY=[other access key]
同样使用 Postman,我没有任何问题,使用https://s3.amazonaws.com/bucket/?prefix=path
和使用 AWS 签名作为授权类型。