为什么AWS不告诉我BucketAlreadyExists?

3ch*_*eel 7 python amazon-s3 amazon-web-services boto3

我正在使用AWS SDK for Python(boto3)自动设置某些AWS服务,并遇到一个非常简单的创建S3存储桶的问题.

我仔细检查过以下内容:

  • ~/.aws/credentials,我有一个访问密钥ID和秘密访问密钥集.
  • 此访问密钥ID /秘密访问密钥用于属于具有以下策略的组的一部分的帐户:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect": "Allow",
          "Action": "*",
          "Resource": "*"
        }
      ]
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • 没有现有的存储桶,其名称是我正在尝试创建存储桶

然而,当我尝试运行这个非常简单的操作时,它失败了:

>>> 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.
Run Code Online (Sandbox Code Playgroud)

我觉得我错过了一些非常愚蠢的事情,但我不能为我的生活想想它可能是什么或我做错了什么.

Shi*_*lts 23

存储桶名称是全局到区域的,并非特定于您的帐户.因此,您需要选择一个根本不存在的名称.我建议使用前缀

  • 哦,我将“系统的所有用户共享”解释为我们帐户中的用户。谢谢,这是完全出乎意料的&gt; _&gt; (3认同)
  • 不是“全局到区域”。只是全球。存储桶名称空间跨越所有S3区域。 (3认同)