Closed jilseph closed 5 years ago
Other than the event being the 'cleaned up' event, this is just logging the event/context params and the response object; this can be achieved in any relevant code by:
const serverless = require('serverless-http');
const app = ...
const handle = serverless(app);
module.exports.handler = async (event, context) {
yourLogger.log(event, context);
const response = await handle(event, context);
yourLogger.log(response);
return response;
};
This can get even simpler if you combine with some of the middleware-style features of @alpha-lambda, i.e. it can become:
const serverless = require('serverless-http');
const handler = require('@alpha-lambda/handler');
const logging = require('e.g.logging-middleware') // we have one of these, but not released to public yet, we should soon
const app = ...
module.exports.handler = handler()
.use(logging())
.use(serverless(app));
};
I'm not super keen on including this console.log behaviour as part of the core library.
Closing as I believe the logging issue can be addressed via middleware/regular functions, not part of this library
Log API Gateway requests and responses for further analysis in CloudWatch Logs Insights.