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!!

asked 2 years ago4345 views
1 Answer
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
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions