I need to return the message sent by Rekognition to SNS but I get this error in CloudWatch:
'Records': KeyError Traceback (most recent call last): File "/var/task/AnalyzeVideo/lambda_function.py", line 34, in lambda_handler message = event["Records"][0]["Sns"]["Message"] KeyError: 'Records'
Code:
def detect_labels(bucket, key):
response = rekognition.start_label_detection(
Video = {
"S3Object": {
"Bucket": BUCKET,
"Name": KEY
}
},
NotificationChannel = {
"SNSTopicArn": TOPIC_ARN,
"RoleArn": ROLE_ARN
}
)
return response
def lambda_handler(event, context):
reko_response = detect_labels(BUCKET, KEY)
message = event["Records"][0]["Sns"]["Message"]
return message
And is this the correct way of implementing Rekognition stored video in AWS Lambda with python I didn't find any examples on it.
Update:
The steps my app needs to take are:
- In the frontend, the user triggers a lambda function with API gateway which sends a file to s3
- When the file arrives trigger the same lambda function to apply video recognition and send jobId to SNS
- when SNS receives a message trigger the same lambda function to get the label data and return the data back to the user with API gateway