When I want to access my S3 bucket using boto3, I simply do this:
import boto3
s3_client = boto3.client('s3')
response = s3_client.list_objects_v2(
Bucket='[bucket name]',
Prefix='[prefix]'
)
But what if I need to access another S3 bucket (not mine but from a client) in another server (using this term as using Cyberduck I can access that S3 having Server = bucket/prefix.s3.amazonaws.com)
?
This solution doesn't seem to be working:
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]'
)
I can access that S3 using Cyberduck without problems (specifying Server, Access Key ID and Secret Key ID), but on script I get access denied
.
I tried specifying any other region adding region_name='[region]'
to boto3.client, but apart from access denied, the other error I got sometimes was An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.
Which doesn't make much sense, because it's the same used in Cyberduck and by bash scripts, following format:
SOURCE_FOLDER=s3://bucket/prefix
SEC_KEY=[other secret key]
ACC_KEY=[other access key]
Also using Postman, I don't have any issue, using https://s3.amazonaws.com/bucket/?prefix=path
and using AWS Signature as Authorization Type.