Skip to content

Latest commit

 

History

History
29 lines (20 loc) · 902 Bytes

long-running-handlers.md

File metadata and controls

29 lines (20 loc) · 902 Bytes

Detecting Handlers than Run for Too Long

For Lambda handlers that must run within a specific time period, you can specify a timeout value. This value will not stop execution of your code, but will detect an error condition.

To use the timeout feature, specify a timeout value in seconds using timeout() as in the example below:

const LambdaTester = require( 'lambda-tester' );

// your favorite validation tool here
const expect = require( 'chai' ).expect;

const myHandler = require( '../index' ).handler;

describe( 'handler', function() {

	it( 'test callback( null, result )', function() {

		return LambdaTester( myHandler )
			.event( { name: 'Fred' } )
			.timeout( 1 /* fail if longer than 1 second */ )
			.expectResult( ( result ) => {

                expect( result.userId ).to.exist;
                expect( result.user ).to.equal( 'fredsmith' );
            });
	});
});