S3 + SNS +構成LAMBDA
數據處理流水線被拒絕becasue S3不能發送notificaiton出它的存儲區域,所以我利用SNS的發送S3通知到其他地區的Lambda。
lambda函數編碼與
from __future__ import print_function
import boto3
def lambda_handler (event, context):
input_file_bucket = event["Records"][0]["s3"]["bucket"]["name"]
input_file_key = event["Records"][0]["s3"]["object"]["key"]
input_file_name = input_file_bucket+"/"+input_file_key
s3=boto3.resource("s3")
obj = s3.Object(bucket_name=input_file_bucket, key=input_file_key)
response = obj.get()
return event #echo first key valuesdf
,當我跑保存和測試,我得到了以下錯誤
{
"stackTrace": [
[
"/var/task/lambda_function.py",
20,
"lambda_handler",
"response = obj.get()"
],
[
"/var/runtime/boto3/resources/factory.py",
394,
"do_action",
"response = action(self, *args, **kwargs)"
],
[
"/var/runtime/boto3/resources/action.py",
77,
"__call__",
"response = getattr(parent.meta.client, operation_name)(**params)"
],
[
"/var/runtime/botocore/client.py",
310,
"_api_call",
"return self._make_api_call(operation_name, kwargs)"
],
[
"/var/runtime/botocore/client.py",
395,
"_make_api_call",
"raise ClientError(parsed_response, operation_name)"
]
],
"errorType": "ClientError",
"errorMessage": "An error occurred (AccessDenied) when calling the GetObject operation: Access Denied"
}
我配置了
full S3 access
,並設置拉姆達角色我的目標存儲桶上的存儲桶政策
everyone can do anything(list, delete, etc.)
看來我還沒有制定好政策。
這很含糊。你能否指出一個人可以解決這個問題? –
兩種可能性 1.針對讀取的S3對象級別權限被拒絕 2.附加到lambda的角色沒有獲取/讀取S3對象的權限 – omuthu
對於我幫助將's3:GetObject'添加到策略中。 –