使用IAM角色通过boto3连接到Amazon S3

6
我想要从Python的boto模块转换为更新的boto3模块,用来操作Amazon S3上的文件。 我还需要像旧的boto模块一样使用Amazon IAM角色。我不确定服务器上的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/

2个回答

阿里云服务器只需要99元/年,新老用户同享,点击查看详情
7

对于所有相关的存储桶,您需要在策略中拥有s3:ListBucket权限。您可以在此处找到完整的S3策略条件列表。


如何使用Python Boto3添加权限? - Utopia

0

这里有一个使用Boto3执行IAM基本任务的好例子,可以在代码示例存储库中找到:

AWS IAM入门示例


始终引用重要链接中最相关的部分。 - b10n1k
虽然这个链接可能回答了问题,但最好在此处包含答案的基本部分并提供参考链接。如果链接页面更改,仅有链接的答案可能会失效。-【来自审查】 - user16217248

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,