Raady
Raady

Reputation: 1726

Unable to create a bucket in s3

I am trying to create a bucket in my s3 with USEast1 as location.

from boto.s3.connection import Location

mybucket = 'test-voip1'
conn = boto.connect_s3(aws_access_key_id, aws_secret_access_key)
if conn.lookup(mybucket) is None:
     conn.create_bucket(mybucket, location=Location.USEast1)
     # conn.create_bucket(mybucket)

When I try to run it gives me an attribute error

Traceback (most recent call last):
   File "s2t_amazon.py", line 146, in <module>
        conn.create_bucket(mybucket, location=Location.USEast1)
AttributeError: type object 'Location' has no attribute 'USEast1'

I am able to connect to create the connection, and I am able to create a bucket with USWest as location. While installing boto I didn't get any error but why I am getting this error?

Even I tried with boto3,

session = boto3.Session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
s3 = session.resource('s3')
s3.create_bucket(Bucket='mybucket', CreateBucketConfiguration={'LocationConstraint': 'us-east-1'})

I get similar error

 botocore.exceptions.ClientError: An error occurred (InvalidLocationConstraint) when calling the CreateBucket operation: The specified location-constraint is not valid

how to resolve the error?

when I try to check the location of other previously created buckets in my s3

bucket = conn.get_bucket('ml-vectors')
bucket.get_location()
>> ''

it gives empty, I am unable to check how the other buckets are created in my s3 which created by others.

Upvotes: 1

Views: 2332

Answers (1)

Konstantin Grigorov
Konstantin Grigorov

Reputation: 1612

The error that you are getting can be understood once you look into the definition of the Location class in the AWS connection.py:

class Location(object):

DEFAULT = ''  # US Classic Region
EU = 'EU'  # Ireland
EUCentral1 = 'eu-central-1'  # Frankfurt
USWest = 'us-west-1'
USWest2 = 'us-west-2'
SAEast = 'sa-east-1'
APNortheast = 'ap-northeast-1'
APSoutheast = 'ap-southeast-1'
APSoutheast2 = 'ap-southeast-2'
CNNorth1 = 'cn-north-1'

As you can see there is no USEast1. The solution to this problem can be found in the quote below:

As per http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUT.html: "If you are creating a bucket on the US East (N. Virginia) region (us-east-1), you do not need to specify the location constraint". Other regions work fine. I can take this up.

You can find the full discussion on: https://github.com/elastic/elasticsearch/issues/16978

Upvotes: 3

Related Questions