I am trying to connect S3 using boto.
I am able to list S3 bucket details using s3 CLI commands but boto is unable to establish connection
boto version: 2.46.1 Python Version: 2.7.12
My code is as follows and the error message is "[Errno 104] Connection reset by peer"
#!/home/python-workdir/python-2.7.12/bin/python
import os, sys
import math
import boto
from boto.s3.key import Key
import boto.s3.connection
AWS_ACCESS_KEY_ID = 'XXXXXXXXXXXXXXXXXXXXX'
AWS_SECRET_ACCESS_KEY = 'YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
Bucketname = 'bucket/private/im/poc/master/1/testbucket'
conn = boto.s3.connect_to_region('ap-southeast-2',
aws_access_key_id=AWS_ACCESS_KEY_ID,
aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
print "conn success"
bucket = conn.get_bucket(Bucketname)
Since you've play with AWS CLI, why don't you start changing your code to boto3, use the ~/.aws/* credentials setup ?
First, if you use aws cli to do this, this include the prefix
aws s3 ls s3://bucket/private/im/poc/master/1/testbucket
So the code should be something like this
import boto3
Bucketname = 'bucket'
prefix = '/private/im/poc/master/1/testbucket'
s3 = boto3.resource("s3")
mybucket = s3.Bucket(Bucketname)
all_object = mybucket.objects.all()