question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

502 Error on Lambda

See original GitHub issue

Hi,

i have a Problem, when i deploy the project to my aws account.

Local -> Everything works fine. AWS -> i get back 502 Internal Server Error.

When i test the AWS Lambda in the online console i get:

Execution log for request test-request Sun May 07 00:24:12 UTC 2017 : Starting execution for request: test-invoke-request Sun May 07 00:24:12 UTC 2017 : HTTP Method: POST, Resource Path: /graphql Sun May 07 00:24:12 UTC 2017 : Method request path: {} Sun May 07 00:24:12 UTC 2017 : Method request query string: {} Sun May 07 00:24:12 UTC 2017 : Method request headers: {} Sun May 07 00:24:12 UTC 2017 : Method request body before transformations: {viewer{id}} Sun May 07 00:24:12 UTC 2017 : Endpoint request URI: https://lambda.eu-central-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:eu-central-1:000000000:function:serverless-myapp-production-api/invocations Sun May 07 00:24:12 UTC 2017 : Endpoint request headers: {x-amzn-lambda-integration-tag=test-request, Authorization=*******************************************************************************************************************************************************************************************************************************************************************************************************************************************39966f, X-Amz-Date=20170507T002412Z, x-amzn-apigateway-api-id=000000000, X-Amz-Source-Arn=arn:aws:execute-api:eu-central-1:000000000:wmxk0au92f/null/POST/graphql, Accept=application/json, User-Agent=AmazonAPIGateway_wmxk0au92f, X-Amz-Security-Token=000000000 [TRUNCATED] Sun May 07 00:24:12 UTC 2017 : Endpoint request body after transformations: {"resource":"/graphql","path":"/graphql","httpMethod":"POST","headers":null,"queryStringParameters":null,"pathParameters":null,"stageVariables":null,"requestContext":{"accountId":"000000000","resourceId":"000000000","stage":"test-invoke-stage","requestId":"test-invoke-request","identity":{"cognitoIdentityPoolId":null,"accountId":"000000000","cognitoIdentityId":null,"caller":"000000000","apiKey":"test-invoke-api-key","sourceIp":"test-invoke-source-ip","accessKey":"abcd","cognitoAuthenticationType":null,"cognitoAuthenticationProvider":null,"userArn":"arn:aws:iam::00000:user/abcd","userAgent":"Apache-HttpClient/4.5.x (Java/1.8.0_112)","user":"000000000"},"resourcePath":"/graphql","httpMethod":"POST","apiId":"000000000"},"body":"{viewer{id}}","isBase64Encoded":false} Sun May 07 00:24:13 UTC 2017 : Endpoint response body before transformations: {"errorMessage":"RequestId: 000000000 Process exited before completing request"} Sun May 07 00:24:13 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=000000000, Connection=keep-alive, Content-Length=107, X-Amz-Function-Error=Unhandled, Date=Sun, 07 May 2017 00:24:12 GMT, X-Amzn-Trace-Id=root=000000000;sampled=0, Content-Type=application/json} Sun May 07 00:24:13 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response Sun May 07 00:24:13 UTC 2017 : Method completed with status: 502

Any ideas? My api folder is pretty the same, as in the example - i only changed the s3 bucket and the region in my serverless.yaml

Greetings Tobias

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
kevuptoncommented, Jul 1, 2017

+1 Managed to solve this using

    events:
         - http:
             path: purchase
             method: post
             cors: true
             integration: LAMBDA <----- // this is what fixed it

This leads me to believe that it is to do with the lambda proxy expecting a different response. And therefore getting a malformed lambda proxy response error.

6reactions
Starling-dacommented, Nov 28, 2017

If a method is Lambda proxy integration then the response body is expected to be JSON object. I had the same issue as I was using JSON.stringify(result) where result was a JSON object. I don’t explicitly specify the integration on the serverless.yml however test run on aws shows 💯 Endpoint request headers: {x-amzn-lambda-integration-tag=test-request

After changing request to result my method started working for the endpoints:

  logger.debug(typeof result); //  Object
  logger.debug(typeof JSON.stringify(result));  // string

  const repsonse = {
    statusCode: 200,
    headers: {
      "Access-Control-Allow-Origin" : "*",
      "Access-Control-Allow-Credentials" : true
    },
    body: result
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I resolve HTTP 502 errors from API Gateway REST ...
If your Lambda function's permissions are incorrect or the response to the API request isn't formatted correctly, then API Gateway returns an ...
Read more >
HTTP 502 status code (Lambda validation error) - 亚马逊云科技
If you're using Lambda@Edge, an HTTP 502 status code can indicate that your Lambda function response was incorrectly formed or included invalid content....
Read more >
AWS Lambda + API-gateway return 502 error when the ...
A 502 error is, as you suggested, returned by the API Gateway when it receives a malformed Lambda proxy response (see ...
Read more >
Internal Server Error/502 Bad Gateway testing a Lambda ...
Set up a Function URL for the Lambda Function and tried calling from PostMan, get a response 'Internal Server Error' with a status...
Read more >
How to troubleshoot 502 and 500 errors when I invoke ... - Quora
Test by API gateway, you will find test button in your resource with the method, click test check the response, then check lambda...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found