Advertisement

python的服务器、客户端被拒绝访问_无服务器AWS(Python)从S3读取:访问被拒绝...

阅读量:

我有一个问题,从我的lambda函数(FrameWork serverless)到AWS中的S3服务的getObject访问 . 这里是我的代码示例:

import boto3

import csv

def hello(event, context):

s3 = boto3.resource('s3')

bucket = s3.Bucket('myBucket')

obj = bucket.Object(key='MOCK_DATA.csv')

response = obj.get()

lines = response['Body'].read().split()

body = []

for row in csv.DictReader(lines):

body.append(row)

return body

在我的serverless.yml中,我给了我的lambda完全访问存储桶

iamRoleStatements:

- Effect: "Allow"

Action:

- "s3:*"

Resource:

- "arn:aws:s3:::myBucket"

但是当我运行代码时,我收到错误:

START RequestId: a6c006b7-21e5-11e8-8193-c3378825927 Version: $LATEST

An error occurred (AccessDenied) when calling the GetObject operation: Access Denied: ClientError

Traceback (most recent call last):

File "/var/task/handler.py", line 5, in hello

response = obj.get()

File "/var/runtime/boto3/resources/factory.py", line 520, in do_action

response = action(self, *args, **kwargs)

File "/var/runtime/boto3/resources/action.py", line 83, in call

response = getattr(parent.meta.client, operation_name)(**params)

File "/var/runtime/botocore/client.py", line 317, in _api_call

return self._make_api_call(operation_name, kwargs)

File "/var/runtime/botocore/client.py", line 615, in _make_api_call

raise error_class(parsed_response, operation_name)

ClientError: An error occurred (AccessDenied) when calling the GetObject operation: Access Denied

你知道为什么boto3不能获得iam角色的许可吗?因为只有当我使用私钥和访问密钥声明boto3时它才起作用:

s3 = boto3.resource('s3',aws_access_key_id='accesskey',aws_secret_access_key='privateKey')

先感谢您

全部评论 (0)

还没有任何评论哟~