Reputation: 726
I am having a problem getting my python lambda function to work. I get an invalid key for the event array that should be created when the skill is invoked. The error I get is:
{
"stackTrace": [
[
"/var/task/lambda_function.py",
163,
"lambda_handler",
"app_id = event['session']['application']['applicationId']"
]
],
"errorType": "KeyError",
"errorMessage": "'session'"
}
and here is my code
def lambda_handler(event, context):
"""Lambda function entrypoint."""
# print("event.session.application.applicationId={}".format(
# event['session']['application']['applicationId']))
# Prevent unwanted access to this Lambda function.
app_id = event['session']['application']['applicationId']
if app_id != "amzn1.ask.skill.yyyyyyyy-xxx":
raise ValueError("Invalid Application ID: {}".format(app_id))
request = event['request']
if event['session']['new']:
on_session_started(
{'requestId': request['requestId']}, event['session'])
func_map = {
"LaunchRequest": on_launch,
"IntentRequest": on_intent,
"SessionEndedRequest": on_session_ended,
}
return func_map[request['type']](event['request'], event['session'])
Upvotes: 2
Views: 2086
Reputation: 1164
We just started a project bstpy to expose a Python lambda as an http service. You may find it useful for testing. You can throw json payloads at it with curl or postman. If you try it with other Bespoken Tools you can a have very nice development environment
Upvotes: 1
Reputation: 726
The problem was I had configured the wrong test in the Lambda Function dashboard. When I changed it to an Alexa Start Session, the event object got created. :)
Upvotes: 5