Python KeyError

0

Hello AWS Team, Can some one please help me here, I am trying to deploy the solution as advised in the blog https://aws.amazon.com/blogs/contact-center/recovering-abandoned-calls-with-amazon-connect/ , however when I run a test on Python 3.7 Lambda code as given, I am getting below error:

Response { "errorMessage": "'Records'", "errorType": "KeyError", "stackTrace": [ " File "/var/task/ACR.py", line 18, in lambda_handler\n for record in event['Records']:\n" ] }

Can some one please assist me with correct "Test Event" i should configure and also how can i get this error resolved? Thanks, Anchal

已提問 2 年前檢視次數 2613 次
3 個答案
0

Hi there,

I have checked the code in the example and event you are looking for is "Kinesis record event", here is an example from documentation:

https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html

You can create an example event for to test your Lambda function locally.

Kind regards,

Alex

profile pictureAWS
已回答 2 年前
0

Hello Thanks for sharing the test event, however please if you can run the code and test it, its giving that KeyError can you please check and validate code provided is correct? As its not recognizing 'Records' in the library for Python?

Regards, Anchal

已回答 2 年前
0

Hi Again,

As you can see after the Kinesis Record, test event i run, the below error i get : { "fail_code": "decode data fail", "result": "fail", "ctrs_processed": 0, "ctrs_skipped": 0 }

Seems its giving payload error in the Lambda function provided?

Decode the data and parse the json

    try:
        payload = base64.b64decode(record['kinesis']['data'])
        payload_data = json.loads(payload)
    
    # Log a decode failure and break out of loop
    except:
        response.update({'fail_code':'decode data fail'})
        response.update({'result':'fail'})

Please if you can help, will be apreciated.

Thanks, Anchal

已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南