aws-lambda-async-handler
v0.1.0
Published
Use async functions for your AWS Lambda handlers
Downloads
2
Readme
AWS Lambda Async Handler
For when you are deploying a Lambda (Node 6.10) which you're compiling using TypeScript or Babel, and you just want to use async/await for your handler.
You're asked to provide...
exports.myHandler = function(event, context, callback) {
...
// Use callback() and return information to the caller.
}
(Source: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html)
But you want your TypeScript to be...
import wrapHandler from 'aws-lambda-async-handler'
export const hello = async (event: AWSLambda.APIGatewayEvent, context: AWSLambda.Context) => {
//...
if (err) {
throw err
}
return result
});
So you just...
import wrapHandler from 'aws-lambda-async-handler'
export const hello = wrapHandler(
async (event: AWSLambda.APIGatewayEvent, context: AWSLambda.Context) => {
//...
if (err) {
throw err
}
return result
});
Or in async compiled JavaScript...
const wrapHandler = require('aws-lambda-async-handler').default
exports.myHandler = wrapHandler(async (event, context) => {
//...
if (err) {
throw err
}
return result
})