3

I am facing a strange issue with a lambda intergration in api gateway ( tried proxy as well same issue)

lambda first hits AppSync and returns either JSON content on error or a XLXS file on success.

while testing on API gateway test console it brings back status 200 and the binary results as expected. but when i try it externally through postman it fails.

More info :

Intergration type : Lambda

Success response :

response = buffer.toString("base64");

Error Response:

response= JSON.stringify(err);

Serverless apigateway setup:

exportXls: 
handler: ./src/apiGatewayLambdas/exportxls/exportXls.handler
role:  AppSyncLambdaRole 
events:
    - http:
        path: /api/exportxls
        method: post
        integration: lambda

        contentHandling: CONVERT_TO_BINARY
ircmgr
  • 77
  • 1
  • 9
  • What are you sending via Postman? Have you checked the Lambda logs? :) – Chris Williams Jun 06 '20 at 14:42
  • 1
    Here is the weird thing that i get no error logs... i only see logs on success from the test console. and few logs i managed to get on cloudwatch they all bring up Sat Jun 06 14:46:31 UTC 2020 : Successfully completed execution Sat Jun 06 14:46:31 UTC 2020 : Method completed with status: 200 ( tested just now) – ircmgr Jun 06 '20 at 14:51
  • Right, have you got API Gateway logs enabled, that might help? – Chris Williams Jun 06 '20 at 14:56
  • 1
    yes the error here after lambda execution success : Method request body before transformations: [Binary Data] Execution failed due to configuration error: Unable to transform request – ircmgr Jun 06 '20 at 14:58
  • Presumably caused by `contentHandling: CONVERT_TO_BINARY` – Chris Williams Jun 06 '20 at 14:59
  • 1
    this is a serverless plugin to enable the convertion . i tried removing it as well and setting explicitly content type and content-disposition but the same issue occurs – ircmgr Jun 06 '20 at 15:03

1 Answers1

0

Apparently Apigateway with lambda or proxy integration encodes body to base64. so i changed my lambda to

let buffer = new Buffer(_event.body, "base64");
let body = buffer.toString("ascii");
body = JSON.parse(body);

and everything worked as expected .

ircmgr
  • 77
  • 1
  • 9