1 réponse
- Le plus récent
- Le plus de votes
- La plupart des commentaires
0
The key in the Event object is names Records
, and not Record
as you wrote. You should reference the object using event["Records"][0]["s3"]["bucket"]["name"]
and event["Records"][0]["s3"]["object"]["key"]
.
Further more, you are testing the code from the console, so you need to provide a valid structured event object. Just choose S3-Put
for the template in the Test event page.
Contenus pertinents
- demandé il y a 6 mois
- demandé il y a 4 mois
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans
- AWS OFFICIELA mis à jour il y a 9 mois
import json import urllib.parse import boto3
print('Loading function') s3 = boto3.client('s3') def lambda_handler(event, context): #print("Received event: " + json.dumps(event, indent=2))
Here is my code -- still getting key error
Response { "errorMessage": "'s3bucket001forlambda01'", "errorType": "KeyError", "stackTrace": [ " File "/var/task/lambda_function.py", line 14, in lambda_handler\n bucket = event["Records"][0]["s3"]["bucket"]['s3bucket001forlambda01']\n" ] }
Function Logs START RequestId: eb0f25c5-e96f-4db0-83b3-702a23203847 Version: $LATEST [ERROR] KeyError: 's3bucket001forlambda01' Traceback (most recent call last): File "/var/task/lambda_function.py", line 14, in lambda_handler bucket = event["Records"][0]["s3"]["bucket"]['s3bucket001forlambda01'] END RequestId: eb0f25c5-e96f-4db0-83b3-702a23203847
You should not include
['s3bucket001forlambda01']
in there. Instead you should use["name"]
, just as I wrote in my example. You get the bucket name and object key from the event object. You should not provide them youself.