46

I am trying to create an S3 bucket using

aws s3api create-bucket —bucket kubernetes-aws-wthamira-io

It gives this error:

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.

I set the region using aws configure to eu-west-1

Default region name [eu-west-1]: 

but it gives the same error. How do I solve this?

I use osx terminal to connect aws

Paweł Prażak
  • 3,091
  • 1
  • 27
  • 42
wthamira
  • 2,032
  • 2
  • 21
  • 40
  • 1
    I am using the `aws s3` and got the same problem output. Try adding `--region` to set constraint helps me fix this problem. Works the same as `LocationConstraint` in s3api – Diya Li Jun 05 '19 at 07:29

10 Answers10

83

try this:

aws s3api create-bucket --bucket kubernetes-aws-wthamira-io --create-bucket-configuration LocationConstraint=eu-west-1

Regions outside of us-east-1 require the appropriate LocationConstraint to be specified in order to create the bucket in the desired region.

https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html

Asdfg
  • 11,362
  • 24
  • 98
  • 175
  • 2
    To be thorough, the example should include the --region option: the command will require BOTH the --region option AND the --create-bucket-configuration option to (redundantly) specify the region, e.g. `aws s3api create-bucket --bucket kubernetes-aws-wthamira-io --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1` – Everett Apr 01 '19 at 17:00
  • @Everett: It worked without the --region option in my case. – Matej Aug 19 '19 at 20:05
  • If anyone is using REST APi directly, then you DON'T need to pass the payload for `us-east-1` location. – Rahul Bharadwaj Dec 09 '20 at 19:05
  • @Matej You only need to specify `--region` if there is a default value defined for the used profile *and* it differs from the `LocationConstraint` value! – rmuller Oct 26 '21 at 10:26
13

Using mb solved the issue for us

aws s3 mb s3://storage.example.com --region us-west-1
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
Nithya
  • 582
  • 8
  • 19
  • This command also has more explicit error message when you are trying to recreate recently deleted bucket: `An error occurred (OperationAborted) when calling the CreateBucket operation: A conflicting conditional operation is currently in progress against this resource. Please try again.` – Roman Shishkin Apr 21 '22 at 14:37
9

You'll also get this error if you're trying to create a bucket with a name that's already been taken.

So try giving your bucket a more unique name and then it should work (I just added digits to the end of the bucket name).

Omar
  • 159
  • 4
  • 5
  • This is not regarding the name, this error occurred due to the region constraint @omari – Umair Khan Jun 25 '21 at 10:25
  • That actually worked in my case. When a bucket name exists, it raises the same error message which is very unintuitive and should be fixed by them. – armiro Mar 24 '22 at 16:21
  • in my case it was exactly the problem - the bucket name existed. – lanenok Jun 09 '22 at 17:45
4

Try this:

aws s3api create-bucket --bucket myhosted-cctestdemowebsitetest.com --acl public-read --create-bucket-configuration LocationConstraint=ap-south-1 --region ap-south-1
AnilS
  • 795
  • 1
  • 11
  • 15
2

I have seen many answers like the first one about "LocationConstraint". The answer is correct, but only covers half the case. I tried to include "LocationConstraint" to solve the problem but still got the same error. It's Omar Zairi's second answer gave me a clue.

The message here is in fact very confusing. When you are trying to create a bucket with a name that's already taken, only when your configured region is the same as the bucket with the already taken name's region, you receive the message "The requested bucket name is not available". Otherwise, you receive "location constraint is incompatible for the region specific endpoint this request was sent to".

To find if a name is already taken, and in case it's taken, which region the bucket with that name is in, look at the DNS record of "the-name.s3.amazonaws.com".

Below I use a taken name "test8765" to show what I mentioned above. Hope this helps whoever got confused like I did.

bing@bingstp:~$ dig test8765.s3.amazonaws.com

; <<>> DiG 9.11.3-1ubuntu1.3-Ubuntu <<>> test8765.s3.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39766
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;test8765.s3.amazonaws.com. IN  A

;; ANSWER SECTION:
test8765.s3.amazonaws.com. 2016 IN  CNAME   s3-us-west-2-w.amazonaws.com.
s3-us-west-2-w.amazonaws.com. 5 IN  A   52.218.216.10

;; Query time: 16 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Thu Jan 03 15:16:11 AEDT 2019
;; MSG SIZE  rcvd: 99

bing@bingstp:~$ aws s3api create-bucket --bucket test8765

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.
bing@bingstp:~$ aws s3api create-bucket --bucket test8765 --create-bucket-configuration LocationConstraint=eu-west-1

An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The eu-west-1 location constraint is incompatible for the region specific endpoint this request was sent to.
bing@bingstp:~$ aws s3api create-bucket --bucket test8765 --create-bucket-configuration LocationConstraint=us-west-2

An error occurred (BucketAlreadyExists) when calling the CreateBucket operation: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.
bing@bingstp:~$ aws s3api create-bucket --bucket test8765 --create-bucket-configuration LocationConstraint=us-west-1

An error occurred (IllegalLocationConstraintException) when calling the CreateBucket operation: The us-west-1 location constraint is incompatible for the region specific endpoint this request was sent to.
bing@bingstp:~$ 
Bing Ren
  • 1,589
  • 17
  • 26
1

Most of the suggestions listed above could be a reason for the IllegalLocationConstraintException error to happen. In my case, the same error happened and solved by creating a new bucket with the same region as that of the code I am working with. For instance, if S3 bucket is created in us-east-1 region, your code e.g., the AWS SageMaker notebook instance has to be also created from us-east-1 region.

ewalel
  • 1,932
  • 20
  • 25
1
s3.create_bucket(Bucket=bucket_name,
                 CreateBucketConfiguration={'LocationConstraint':'us-west-2'})

If your location is not 'us-east-1' (the default) you must use CreateBucketConfiguration={'LocationConstraint':'your location'}.

Lutz Prechelt
  • 36,608
  • 11
  • 63
  • 88
Bishal Roy
  • 11
  • 1
1

Try this : Add bucket name with number Please check screenshot 1

aws s3 mb s3://name67 --region us-east-1

Refer for more here AWS Docs2

Akhil
  • 11
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 26 '23 at 00:30
0

I'm also facing the same problem. Change the bucket name and try. It worked for me.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
0

I got this error when using:

aws s3 mb s3:// --region us-east-1

Adding numbers to the bucket name fixed it for me.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 24 '22 at 10:21