2016-01-20 97 views
4

我正嘗試從python boto轉移到新的boto3模塊,用於在Amazon S3上操作文件。用boto3與IAM角色連接到Amazon S3

我還需要使用Amazon IAM角色,就像我在舊的boto模塊中一樣。我不知道的IAM角色是如何設置的服務器上,但我不得不這樣做是:

s3_conn = S3Connection() 

,我會得到所有的服務器可以訪問分區的訪問。

這似乎是在boto3不同:

s3 = boto3.resource('s3') 
for bucket in s3.buckets.all(): 
    print(bucket.name) 

我得到一個錯誤:

File "<stdin>", line 1, in <module> 
File "/usr/local/lib/python2.7/dist-packages/boto3/resources/collection.py", line 83, in __iter__ 
    for page in self.pages(): 
File "/usr/local/lib/python2.7/dist-packages/boto3/resources/collection.py", line 161, in pages 
    pages = [getattr(client, self._py_operation_name)(**params)] 
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 310, in _api_call 
    return self._make_api_call(operation_name, kwargs) 
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 407, in _make_api_call 
    raise ClientError(parsed_response, operation_name) 
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied 

我通過boto3文檔去,但我不知道我需要做的設置了IAM角色:

http://boto3.readthedocs.org/en/latest/

回答

6

您將需要s3:ListBucket在您的政策中允許所有相關的存儲桶。您可以找到S3政策條件的完整列表here

+0

如何使用Python Boto3添加權限? – Utopia