Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is AWS telling me BucketAlreadyExists when it doesn't?

I'm in the process of automating the setup of some AWS services using AWS SDK for Python (boto3) and running into a very simple problem of creating an S3 bucket.

I've double-checked the following:

  • In ~/.aws/credentials, I have an Access Key ID and Secret Access Key set.
  • This access key ID/secret access key is for an account that is part of a group with the following policy attached:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "*",
          "Resource": "*"
        }
      ]
    }
    
  • There is no existing bucket with the name I'm trying to create the bucket with

Yet when I try to run this very simple operation, it fails:

>>> import boto3
>>> client = boto3.client('s3')
>>> response = client.create_bucket('staging')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yiqing/Repos/ansible-home/roles/osx/files/virtualenvs/obaku/lib/python2.7/site-packages/botocore/client.py", line 157, in _api_call
    "%s() only accepts keyword arguments." % py_operation_name)
TypeError: create_bucket() only accepts keyword arguments.
>>> response = client.create_bucket(Bucket='staging')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yiqing/Repos/ansible-home/roles/osx/files/virtualenvs/obaku/lib/python2.7/site-packages/botocore/client.py", line 159, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/yiqing/Repos/ansible-home/roles/osx/files/virtualenvs/obaku/lib/python2.7/site-packages/botocore/client.py", line 494, in _make_api_call
    raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: 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.

I feel like I'm missing something very silly but can't for the life of me think of what it might be or what I'm doing wrong.

like image 648
3cheesewheel Avatar asked Aug 19 '16 17:08

3cheesewheel


1 Answers

A bucket name is global to region and not specific to your account. So you need to choose a name that doesnt exist at all. I recommend using a prefix

like image 185
Shimon Tolts Avatar answered Sep 30 '22 02:09

Shimon Tolts