aws-step-function-tester v1.1.0
aws-step-function-tester
This is a Node.js library designed to facilitate testing of AWS Step Functions. It provides utilities and commands to interact with AWS services, allowing developers to simulate and validate the behavior of their serverless applications. The library is built using TypeScript and includes dependencies for AWS SDK clients.
The Problem
Testing AWS Step Functions can be challenging due to several reasons:
Complexity: Step Functions can involve multiple states and transitions, making it difficult to cover all possible execution paths and edge cases.
- Error handling: Properly simulating and testing error scenarios, such as timeouts and service failures, requires additional effort to ensure the Step Function behaves as expected.
- Simulation and mocking: Using the Real AWS Step Functions with Mocks can be challenging
Solution - aws-step-function-tester
The main idea of this library is to create an intuitive API based on AWS-SDK for testing real Step Function running on your AWS account. Just like Jest or Chai for AWS Step Function but with high fidelity with easy setup and integration with existing E2E tests you have.
Features
- Copy and manipulate AWS Step Functions for testing purposes
- Create mocks of Lambda functions and integrate them into your copy of Step Function
- Simulate various Lambda execution scenarios (e.g., timeouts, memory overload)
- Mock behavior of other AWS services (e.g., S3, SQS)
- Inspect Step Function execution and status
How To Use
const copyStepFunction: SfnInstance = await createCopyStepFunction("original-step-function-ARN");
const lambdaMock: LambdaMock = await createLambdaMock("original-lambda-name");
await lambdaMock.memoryOverload();
await lambdaMock.timeout();
await lambdaMock.throttle();
await lambdaMock.custom("path/to/source/code", "handler");
await lambdaMock.reset();
await copyStepFunction.mockLambdaStep("step-name", lambdaMock);
const execution: SfnExecution = await copyStepFunction.execute();
await expect(execution).toFail();
await expect(execution).toExecuteStep("Log Timeout Error");
await expect(execution).toExecuteStep("Fail");
Limitations
- Relatively slow due to network latency and communication with AWS service.
- Cost for using real Step Functions, Lambda, and other resources.
- Mocking of AWS services is limited, and not all cases can be covered