AWS Api-Gateway error 500 on postman / success on api gateway test

Viewed 1175

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

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 .

Related