0
votes

I just started with AWS and i am creating my first Lambda functions. The first one was success - no issues when creating and executing. Now i am trying to create Lambda function (python 3 based) with couple parameters. When i perform test from the API Gateway i can see it executes ok. When i try to execute from browser i see the following error: { "errorMessage": "'foo2", "errorType": "KeyError", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 6, in lambda_handler\n foo2 = event['foo2'];\n" ] }

Here is the function and mapping templates:

import json
import sys

def lambda_handler(event, context):
    foo1 = event['foo1'];
    foo2 = event['foo2'];
    foo3 = event['foo3'];
    foo = "This is Test!";

    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps(event)
    }

Mapping template

#set($inputRoot = $input.path('$'))
{ 
    "foo1": "$input.params('foo1')",
    "foo2": "$input.params('foo2')",
    "foo3": "$input.params('foo3')"
}

I really wonder why this is happening..

1

1 Answers

1
votes

I'm not an API gateway wizard, but it looks like you are trying to assign the variable foo2 to a part of the event that doesn't exist when invoking the function from the Browser, when testing the event you might want to look at the structure of the event. It might help inside your Lambda function to add a json.dumps direct under the lambda_handler to try understand if there are missing parameters.