私は単にS3バケットのアップロードされたイベントの著者およびメタデータをプリントアウトするため、次のラムダ関数のコードを持っている:「KeyError例外: 『レコード』」AWS S3で - ラムダトリガ
from __future__ import print_function
import json
import urllib
import boto3
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# bucket = event['Records'][0]['s3']['bucket']['name']
for record in event['Records']:
bucket = record[0]['s3']['bucket']['name']
key = record[0]['s3']['object']['key']
response = s3.head_object(Bucket=bucket, Key=key)
logger.info('Response: {}'.format(response))
print("Author : " + response['Metadata']['author'])
print("Description : " + response['Metadata']['description'])
しかし、I
{
"stackTrace": [
[
"/var/task/lambda_function.py",
17,
"lambda_handler",
"for record in event['Records']:"
]
],
"errorType": "KeyError",
"errorMessage": "'Records'"
}
S3オブジェクトのバケット名とキー名にアクセスする際に何か問題がありますか?そうでなければ、私はここで間違って何をしていますか?
どのようなタイプのS3イベントトリガーを使用していますか? – franklinsijo
@franklinsijo 'イベントの種類:ObjectCreated' – Dawny33
これはテストイベントか実際のイベントですか?あなたは 'イベント'を印刷し、 'レコード'が含まれているかどうか確認できますか? – franklinsijo