0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey thanks for the suggestion. I actually ended up creating new Lambda with the same options and it worked WTF o.0 So then i re-created the API Gateway on the original function and it started working too!
Okay no probs, glad to hear it :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.