Unit/Integration tests for AWS Lambda handlers
npm install lambda-tester

Simplifies writing unit tests for AWS Lambda functions using Node.js.
LAMBDA_TASK_ROOT to the application's rootnpm install lambda-tester --save-dev
Lambda handlers with support for callbacks use the typical Node.js asynchronous signature:
``js
exports.handler = function( event, context, callback ) {
callback( null, 'success!' );
}
`
The following example shows a simple case for validating that the Lambda (handler) was called successfully (i.e. callback( null, result ):
`js
const LambdaTester = require( 'lambda-tester' );
const myHandler = require( '../index' ).handler;
describe( 'handler', function() {
it( 'test success', async function() {
await LambdaTester( myHandler )
.event( { name: 'Fred' } )
.expectResult();
});
});
`
If the handler calls callback( err ), then the test will fail.
Additionally, if one wanted to test for failure, then the following code would be used:
`js
const LambdaTester = require( 'lambda-tester' );
const myHandler = require( '../index' ).handler;
describe( 'handler', function() {
it( 'test failure', async function() {
await LambdaTester( myHandler )
.event( { name: 'Unknown' } )
.expectError();
});
});
`
Note: you must either return the LambdaTester instance back to the testingawait
framework or use the /async keywords.
Complete documentation can be found in our documentation page.
* vandium - Secures and simplifies AWS Lambda handlers
We'd love to get feedback on how you're using lambda-tester and things we could add to make this tool better. Feel free to contact us at feedback@vandium.io`
Starting with version 4.0, lambda-tester supports node versions 10 and higher. If you require support for older versions of node, then use a previous version of lambda-tester.