Reputation: 1091
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:
Upvotes: 1
Views: 2101
Reputation: 269081
Your function is calling rekognition.start_label_detection()
(and presumably you have created the rekognition
client in code not shown).
This API call starts label detection on a video. When it is finished, it will publish a message to the given SNS topic. You can connect a Lambda function to SNS to retrieve the details of the label detection when it is finished.
However, your code is getting the order of operations mixed up. Instead, you should be doing the following:
start_label_detection()
to begin the process of scanning the video. This can take several minutes.get_label_detection()
to retrieve the details of the scan.So, your first step is to separate the initial start_label_detection()
request from the code that retrieves the results. Then, modify the Lambda function to retrieve the results via get_label_detection()
and process the results.
Upvotes: 2