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 年前4376 查看次数
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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则