Handler error python lambda function

0

I am trying to follow this tutorial https://aws.amazon.com/blogs/machine-learning/build-your-own-text-to-speech-applications-with-amazon-polly/ but keep having an error on my lambda functions when I click the 'test' button. My code is the "PostReader_ConvertToAudio" section of the tutorial.

My error code is as follow :

{
  "errorMessage": "'Records'",
  "errorType": "KeyError",
  "requestId": "9e788dd8-763c-4e85-b5c5-36520aeee1ca",
  "stackTrace": [
    "  File \"/var/task/lambda_function.py\", line 8, in lambda_handler\n    postId = event[\"Records\"][0][\"Sns\"][\"Message\"]\n"
  ]
}

Thank you for your help!!

已提問 2 年前檢視次數 4375 次
1 個回答
0

The blog post doesn't explicitly provide example test data to test this function, unlike the other two functions in the post. This is because the function is relying on the data structure provided by the SNS invocation. SNS will invoke this function when a message is received and provide said message to the function; event["Records"][0]["Sns"]["Message"] is where the message will be found.

If you would like to run a test of this function, you will need to emulate the JSON data structure expected by the function:

{
    "Records": [
        {
            "Sns": {
                "Message": "ENTER RELEVANT DATA HERE"
            }
        }
    ]
}
AWS
已回答 2 年前

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

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

回答問題指南