probot / adapter-aws-lambda-serverless

An extension for running Probot on Lambda
ISC License
93 stars 36 forks source link

Incorrect handling of base64 encoded request body from ApiGatway integration #32

Closed nimrodolev closed 4 years ago

nimrodolev commented 4 years ago

In short

When data from the body property of a request from ApiGatway is base64 encoded, it is not being read correctly and an exception is thrown.

More details

When using protobot/serverless-lambda inside an AWS lambda function via and AWS ApiGatway proxy integration, the request body may be sent to the function as a base64 encoded string. The event data contains a dedicated field, isBase64Encoded, meant to indicate this. This field is not being read, and so we make an attempt to parse the body as JSON without decoding it first, causing an exception to be thrown.

Quick workaround

Replacing the handler.js example suggested in the readme with something like this solves the issue -

const { serverless } = require('@probot/serverless-lambda')
const appFn = require('./')
var app = serverless(appFn)
module.exports.probot = function (request: any, context: any, callback: any) {
    if (request.isBase64Encoded) {
        request.body = Buffer.from(request.body, "base64").toString('utf8');
    }
    app(request, context, callback);
}
JasonEtco commented 4 years ago

Closed by #33!