An AWS lambda function has an "event" and a "context" as in parameters. The "event" is a json object.

I try to connect an API (manager through the AWS API Gateway) to my lambda function, sending the json of the event as the body of an http POST. This fails miserably, and I just have some indication that there might be an empty event sent to the lambda function.

How should I send the "event" through the API?

This is the code of my lambda function:

from __future__ import print_function

import boto3
import json
import time

print('Loading function')

def lambda_handler(event, context):
    print("Received event: ")
    print(""+json.dumps(event, indent=2))

    id = event['Id']
    dynamo = boto3.resource('dynamodb').Table('Table1')
        Item = {
        'Button' : int(id),
        'Time' : int(time.time()),
    return {
        'statusCode' : '400',
        'body' : null,
        'headers' : { 'Content-Type': 'application/json', },

Running a test on the lambda function gives the following log:

START RequestId: x Version: $LATEST
Received event: 
<type 'dict'>
  "Id": "1"
END RequestId: x

and the answer

   "body": null,
   "headers": {
     "Content-Type": "application/json"
  "statusCode": "400"

but running it through the API Gateway test function gives

Tue May 16 15:54:27 UTC 2017 : Endpoint response body before transformations: 
  {"stackTrace": [["/var/task/lambda_function.py", 12, "lambda_handler", 
   "id = event['Id']"]], "errorType": "KeyError", "errorMessage": "'Id'"}
Tue May 16 15:54:27 UTC 2017 : Endpoint response headers: 
  {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=x, 
   Connection=keep-alive, Content-Length=153,
   X-Amz-Function-Error=Unhandled, Date=Tue, 16 May 2017 15:54:27 GMT, 
   X-Amzn-Trace-Id=root=x;sampled=0, Content-Type=application/json}
Tue May 16 15:54:27 UTC 2017 : Execution failed due to configuration 
   error: Malformed Lambda proxy response
Tue May 16 15:54:27 UTC 2017 : Method completed with status: 502
  • 2
    Better place to ask this would be stackoverflow site.
    – bravokeyl
    Commented May 16, 2017 at 14:52
  • 1
    How are you invoking Lambda function? Enable cloudwatch logs for the API and check, also check logs for lambda function, that will give you an idea of what's wrong.
    – bravokeyl
    Commented May 16, 2017 at 14:54
  • @Bex KeyError means key 'Id' is missing from the event parameter. What do you mean by "running it through the API Gateway" exactly? You make the mistake on that part.
    – mico
    Commented May 17, 2017 at 11:31
  • Show your effort on that part too.
    – mico
    Commented May 17, 2017 at 11:41
  • @Bex did you manage to fix this already? Could you please share what was the solution?
    – mico
    Commented Jul 26, 2017 at 7:24

1 Answer 1


After some more investigation I found out that 502 error may happen if body is not in quotes.

Your null should be


AWS lambda api gateway error "Malformed Lambda proxy response"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.