Unable to connect aws s3 bucket using boto

You can also use the following (boto.s3.connect_to_region):

import boto
from boto.s3.key import Key
import boto.s3.connection

AWS_ACCESS_KEY_ID = '<access key>'
AWS_SECRET_ACCESS_KEY = '<my secret key>'
Bucketname = 'Bucket-name' 


conn = boto.s3.connect_to_region('ap-southeast-1',
       aws_access_key_id=AWS_ACCESS_KEY_ID,
       aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
       is_secure=True,               # uncomment if you are not using ssl
       calling_format = boto.s3.connection.OrdinaryCallingFormat(),
       )
bucket = conn.get_bucket(Bucketname)

This way you don't have to care about the 'exact' endpoint with the full hostname. And yes like @garnaat mentioned, use the latest boto API.


from boto3.session import Session

ACCESS_KEY='your_access_key'

SECRET_KEY='your_secret_key'

session = Session(aws_access_key_id=ACCESS_KEY,aws_secret_access_key=SECRET_KEY)

s3 = session.resource('s3')

my_bucket = s3.Bucket('bucket_name')

for s3_file in my_bucket.objects.all():

           print(s3_file.key)