Big*_*337 1 amazon-s3 boto amazon-web-services boto3
另外,我将其作为存储桶策略:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::manga-learn-data",
"arn:aws:s3:::manga-learn-data/*"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
我在〜/ .aws / config文件中有这个:
[default]
region=us-west-2
Run Code Online (Sandbox Code Playgroud)
这在我的〜/ .aws / credentials文件中:
[default]
aws_access_key_id = <access-key>
aws_secret_access_key = <secret-key>
Run Code Online (Sandbox Code Playgroud)
现在我做:
>>> import boto3
>>> s3 = boto3.resource('s3')
>>> s3.buckets.all()
s3.bucketsCollection(s3.ServiceResource(), s3.Bucket)
>>> for bucket in s3.buckets.all():
... print(bucket.name)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/alex/anaconda2/lib/python2.7/site-packages/boto3/resources/collection.py", line 83, in __iter__
for page in self.pages():
File "/Users/alex/anaconda2/lib/python2.7/site-packages/boto3/resources/collection.py", line 161, in pages
pages = [getattr(client, self._py_operation_name)(**params)]
File "/Users/alex/anaconda2/lib/python2.7/site-packages/botocore/client.py", line 262, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/alex/anaconda2/lib/python2.7/site-packages/botocore/client.py", line 552, in _make_api_call
raise ClientError(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
Run Code Online (Sandbox Code Playgroud)
您会在那里看到回溯。我正在执行以下步骤:https://github.com/boto/boto3
有什么建议么?
您的代码当前尝试列出所有存储桶,但IAM用户没有这样做的权限。
您要么必须向ListAllMyBuckets您的IAM用户授予访问权限,例如:
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
Run Code Online (Sandbox Code Playgroud)
或者您需要更改代码以仅访问您感兴趣的存储桶:
bucket = s3.Bucket('manga-learn-data')
for object in bucket:
# do whatever you need to do here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5928 次 |
| 最近记录: |