- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
Hi,
By default, the boto3 create_bucket call (with just the bucket name as the parameter) will attempt to create the bucket in the default "us-east-1" region.
You will need to add the following to your boto3 create bucket call:
CreateBucketConfiguration={'LocationConstraint': '<same region as your specified default>'})
You most likely followed the directions to setup your credentials and specified the AWS_DEFAULT_REGION as something other than "us-east-1".
Link: https://docs.aws.amazon.com/cloud9/latest/user-guide/credentials.html
For example, if you set your default location to "us-east-2" and then ran
import boto3
s3 = boto3.client('s3')
s3.create_bucket(Bucket='mybucket-sdfslkjd')
You would get the error:
Traceback (most recent call last):
File "/home/ec2-user/environment/createBucket.py", line 4, in <module>
s3.create_bucket(Bucket='lddidddddd')
File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python3.6/site-packages/botocore/client.py", line 661, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The unspecified location constraint is incompatible for the region specific endpoint this request was sent to.
Now if you add the LocationConstraint to the create-bucket call to explicitly create the bucket in the "us-east-2" region, it would work properly.
import boto3
s3 = boto3.client('s3')
s3.create_bucket(Bucket='lddidddddd',
CreateBucketConfiguration={'LocationConstraint': 'us-east-2'})
Process exited with code: 0
And the bucket gets created in region us-east-2.
Hope this helps!
-randy
Many thanks randy! That fixed the problem and your explanation made sense
cheers
Jon
Contenuto pertinente
- AWS UFFICIALEAggiornata un anno fa
- AWS UFFICIALEAggiornata un anno fa
- AWS UFFICIALEAggiornata 7 mesi fa