Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Malformed Lambda proxy response from AWS API Gateway calling a Lambda

Tags:

In my project i create a py function for check and modify my google calendar like this:

def main(event, context):      ck_app = check(event['calID'], event['datada'], event['dataa'])      if not ck_app: insert(event['calID'], event['datada'], event['dataa'], event['email'])      return {         "isBase64Encoded": False,         "statusCode": '200',         "headers": {},         "body": {'input': event,                  'busy': ck_app,                  'guest_email': event['email']}        } 

when i test it on my lambda all done, but whe i create an API from lambda:

enter image description here

and test it the result is:

Wed Dec 20 13:35:58 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response Wed Dec 20 13:35:58 UTC 2017 : Method completed with status: 502

Thanks in advance

like image 868
AleMal Avatar asked Dec 20 '17 13:12

AleMal


People also ask

How do you handle errors in Lambda API gateway?

Make sure that you also set up the corresponding error code ( 400 ) on the method response. Otherwise, API Gateway throws an invalid configuration error response at runtime. At runtime, API Gateway matches the Lambda error's errorMessage against the pattern of the regular expression on the selectionPattern property.

What is 4xx error in API gateway?

As Marcin said, 4xx errors are typically meaning the client did not make a correct request... you can go into your API Gateway stage and enable the entire request string to be logged for each request... you can then have that to help debug.

Can API gateway invoke Lambda?

You can create a web API with an HTTP endpoint for your Lambda function by using Amazon API Gateway. API Gateway provides tools for creating and documenting web APIs that route HTTP requests to Lambda functions. You can secure access to your API with authentication and authorization controls.

What is Lambda proxy?

The Lambda proxy integration allows the client to call a single Lambda function in the backend. The function accesses many resources or features of other AWS services, including calling other Lambda functions.


1 Answers

API Gateway expects a json body so you should use something like this

import json return {     'statusCode': 200,     'body': json.dumps({'input': event,                         'busy': ck_app,                         'guest_email': event['email']}) } 

Hope this helps you forward.

like image 164
Liam Avatar answered Oct 14 '22 02:10

Liam