I am using boto3 python module to access S3.

Creating bucket works in windows but not working in ubuntu.

It throws the error given below,

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://bucket_name.s3.amazonaws.com/"

Sample code:

aws_access_key = ""
aws_secret_key = ""
s3_region = "us-east-1"

s3_connection = boto3.client('s3', aws_access_key_id=aws_access_key,
                             aws_secret_access_key=aws_secret_key,
                             region_name=s3_region)
s3_connection.create_bucket(Bucket='bucket_name')

1 Answers

0
John Rotenstein On

The error message is suggesting that region_name = 'bucket_name', which does not match the code you have shown us.

Also, please note that it is considered unwise to put credentials in your source code. Instead you should use the AWS Command-Line Interface (CLI) aws configure command to store credentials in ~.aws/credentials. You can then remove them from your code.

You can then run this code to create the bucket:

import boto3

s3_client = boto3.client('s3', region_name='us-east-1')

s3_client.create_bucket(Bucket='foo')