aws-lambda-test-utils is a JavaScript utility library designed to simplify the local testing of AWS Lambda functions. It provides helper functions to mock the `context` object and various AWS service `event` objects (e.g., S3, SNS, DynamoDB, API Gateway) that a Lambda function typically receives. This allows developers to run their Lambda logic outside of the AWS environment for faster, automated testing. The current stable version is 1.3.0. As of the provided information, it primarily supports CommonJS imports, and its release cadence appears to be infrequent, given the version number and the project's age (last commit several years ago). Its key differentiator is its focus on providing simple, predefined mocks for common AWS event types, reducing the boilerplate needed for basic Lambda unit tests, particularly for projects still relying on older callback-style Lambda handlers.
npm install aws-lambda-test-utilsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `mockContextCreator` to simulate an AWS Lambda execution context with both default and custom options, enabling local testing of a callback-style Lambda handler with a specific event payload. This setup is typical for unit testing Lambda functions outside of the AWS environment.
Use CommonJS `require()` syntax: `const { symbol } = require('aws-lambda-test-utils');` or configure your build system (e.g., Webpack, Rollup) to correctly transpile CJS modules for ESM usage.Review the package's source code and current AWS Lambda documentation to ensure compatibility with your specific use case. For new projects or those using modern AWS features, consider more actively maintained alternatives or be prepared to extend/fork this package.
When testing `async/await` Lambda handlers, ensure your test setup correctly awaits the handler's returned promise and maps its resolution/rejection to your test expectations, potentially wrapping the `mockContextCreator` callback to resolve a promise.
Change your import statement to use CommonJS `require()`: `const { mockContextCreator } = require('aws-lambda-test-utils');`Ensure the `mockContextCreator` is provided with a valid callback function as its second argument (`mockContextCreator(options, callback)`). Verify that your Lambda handler correctly calls `context.succeed()` or `context.fail()` when using the callback pattern.
No dependency data recorded yet.