- Two s3 buckets are created in N.Virgenia region.
- Lambda Function created using Python
- file data has to be checked in bucket 1 and compare that data with file which is available in bucket 2 if changes found transfer them to bucket 2 from bucket 1 of file
- if there are no modifications in file or new file added -- lambda should trigger and that new should be transferred to bucket 2
Trying to implementing the above scenario getting below error, Any idea on below error please
Response
{
"errorMessage": "'Record'",
"errorType": "KeyError",
"requestId": "6be014f1-c78c-4a9b-9728-5873b1080812",
"stackTrace": [
" File "/var/task/lambda_function.py", line 9, in lambda_handler\n file_obj = event["Record"][0]["s3bucket001forlambda01"]\n"
]
}
Function Logs
START RequestId: 6be014f1-c78c-4a9b-9728-5873b1080812 Version: $LATEST
Event : {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
[ERROR] KeyError: 'Record'
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.