|
1 | 1 | # AWS Durable Execution SDKs for JavaScript |
2 | 2 |
|
| 3 | +[](https://github.com/aws/aws-durable-execution-sdk-js/actions/workflows/build.yml) |
| 4 | +[](https://www.npmjs.com/package/@aws/durable-execution-sdk-js) |
3 | 5 | [](https://scorecard.dev/viewer/?uri=github.com/aws/aws-durable-execution-sdk-js) |
| 6 | +[](https://opensource.org/licenses/Apache-2.0) |
| 7 | +[](https://nodejs.org/) |
4 | 8 |
|
5 | 9 | --- |
6 | 10 |
|
7 | | -This repository contains the code for the following 3 packages published to NPM: |
| 11 | +Build **resilient, long-running AWS Lambda functions** with automatic state persistence, retry logic, and workflow orchestration. Lambda durable functions can run for up to one year while maintaining reliable progress through checkpoints and automatic failure recovery. |
8 | 12 |
|
9 | | -- [@aws/durable-execution-sdk-js](https://github.com/aws/aws-durable-execution-sdk-js/tree/main/packages/aws-durable-execution-sdk-js) |
10 | | -- [@aws/durable-execution-sdk-js-testing](https://github.com/aws/aws-durable-execution-sdk-js/tree/main/packages/aws-durable-execution-sdk-js-testing) |
11 | | -- [@aws/durable-execution-sdk-js-eslint-plugin](https://github.com/aws/aws-durable-execution-sdk-js/tree/main/packages/aws-durable-execution-sdk-js-eslint-plugin) |
| 13 | +## ✨ Key Features |
12 | 14 |
|
13 | | -The repository also contains example durable functions located [here](https://github.com/aws/aws-durable-execution-sdk-js/tree/main/packages/aws-durable-execution-sdk-js-examples). |
| 15 | +- **Durable Execution** – Automatically persists state and resumes from checkpoints after failures |
| 16 | +- **Automatic Retries** – Configurable retry strategies with exponential backoff and jitter |
| 17 | +- **Workflow Orchestration** – Compose complex workflows with steps, child contexts, and parallel execution |
| 18 | +- **External Integration** – Wait for callbacks from external systems (human-in-the-loop, webhooks) |
| 19 | +- **Batch Operations** – Process arrays with concurrency control and completion policies |
| 20 | +- **Cost Efficient** – Pay only for active compute time; waits suspend without charges |
| 21 | +- **Type Safety** – Full TypeScript support with comprehensive type definitions |
14 | 22 |
|
15 | | -## Documentation |
| 23 | +## 📦 Packages |
16 | 24 |
|
17 | | -- **[API Reference](./docs/api-reference/index.md)** - Complete technical reference with detailed type definitions and operation specifications |
| 25 | +This monorepo contains the following NPM packages: |
18 | 26 |
|
19 | | -## Security |
| 27 | +| Package | Description | NPM | |
| 28 | +| ---------------------------------------------------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 29 | +| [@aws/durable-execution-sdk-js](./packages/aws-durable-execution-sdk-js) | Core SDK for building durable Lambda functions | [](https://www.npmjs.com/package/@aws/durable-execution-sdk-js) | |
| 30 | +| [@aws/durable-execution-sdk-js-testing](./packages/aws-durable-execution-sdk-js-testing) | Testing utilities for local development and CI/CD | [](https://www.npmjs.com/package/@aws/durable-execution-sdk-js-testing) | |
| 31 | +| [@aws/durable-execution-sdk-js-eslint-plugin](./packages/aws-durable-execution-sdk-js-eslint-plugin) | ESLint rules for durable function best practices | [](https://www.npmjs.com/package/@aws/durable-execution-sdk-js-eslint-plugin) | |
20 | 32 |
|
21 | | -See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. |
| 33 | +## 🚀 Quick Start |
22 | 34 |
|
23 | | -## License |
| 35 | +### Installation |
24 | 36 |
|
25 | | -This project is licensed under the Apache-2.0 License. |
| 37 | +```bash |
| 38 | +npm install @aws/durable-execution-sdk-js |
| 39 | +``` |
| 40 | + |
| 41 | +### Your First Durable Function |
| 42 | + |
| 43 | +```typescript |
| 44 | +import { |
| 45 | + withDurableExecution, |
| 46 | + DurableContext, |
| 47 | +} from "@aws/durable-execution-sdk-js"; |
| 48 | + |
| 49 | +const handler = async (event: any, context: DurableContext) => { |
| 50 | + // Use the context logger for structured logging |
| 51 | + context.logger.info("Starting workflow", { userId: event.userId }); |
| 52 | + |
| 53 | + // Execute a durable step with automatic retry |
| 54 | + const userData = await context.step("fetch-user", async (stepCtx) => { |
| 55 | + // Step-scoped logger includes step metadata |
| 56 | + stepCtx.logger.debug("Fetching user from database"); |
| 57 | + return fetchUserFromDB(event.userId); |
| 58 | + }); |
| 59 | + |
| 60 | + // Wait for 5 seconds (no compute charges during wait) |
| 61 | + await context.wait({ seconds: 5 }); |
| 62 | + |
| 63 | + // Process data in another step |
| 64 | + const result = await context.step("process-user", async (stepCtx) => { |
| 65 | + return processUser(userData); |
| 66 | + }); |
| 67 | + |
| 68 | + context.logger.info("Workflow completed", { result }); |
| 69 | + return result; |
| 70 | +}; |
| 71 | + |
| 72 | +export const lambdaHandler = withDurableExecution(handler); |
| 73 | +``` |
| 74 | + |
| 75 | +## 📚 Documentation |
| 76 | + |
| 77 | +- **[AWS Documentation](https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html)** – Official AWS Lambda durable functions guide |
| 78 | +- **[SDK README](./packages/aws-durable-execution-sdk-js/README.md)** – Detailed SDK usage guide with code examples |
| 79 | +- **[API Reference](./docs/api-reference/index.md)** – Complete technical reference with type definitions |
| 80 | +- **[Concepts & Use Cases](./packages/aws-durable-execution-sdk-js/src/documents/CONCEPTS.md)** – Replay model, best practices, and real-world patterns |
| 81 | +- **[Examples](./packages/aws-durable-execution-sdk-js-examples)** – Working examples including hello-world, callbacks, parallel processing, and more |
| 82 | + |
| 83 | +## 🧪 Testing |
| 84 | + |
| 85 | +The testing SDK enables local development and unit testing without deploying to AWS, as well as cloud testing against deployed Lambda functions: |
| 86 | + |
| 87 | +```bash |
| 88 | +npm install @aws/durable-execution-sdk-js-testing --save-dev |
| 89 | +``` |
| 90 | + |
| 91 | +```typescript |
| 92 | +import { LocalDurableTestRunner } from "@aws/durable-execution-sdk-js-testing"; |
| 93 | + |
| 94 | +// Create runner with skipTime to fast-forward through waits |
| 95 | +const runner = new LocalDurableTestRunner({ |
| 96 | + handlerFunction: myDurableHandler, |
| 97 | +}); |
| 98 | +await runner.setupTestEnvironment({ skipTime: true }); |
| 99 | + |
| 100 | +const result = await runner.run({ userId: "123" }); |
| 101 | + |
| 102 | +// Assert execution status |
| 103 | +expect(result.getStatus()).toBe("SUCCEEDED"); |
| 104 | +expect(result.getResult()).toEqual({ processedUser: "..." }); |
| 105 | + |
| 106 | +// Assert number of Lambda invocations (initial+replay after wait) |
| 107 | +expect(result.getInvocations().length).toBe(2); |
| 108 | + |
| 109 | +// Assert operations executed |
| 110 | +const operations = result.getOperations(); |
| 111 | +expect(operations.length).toBe(3); // 2 steps + 1 wait |
| 112 | + |
| 113 | +// Inspect individual operations |
| 114 | +const fetchStep = runner.getOperation("fetch-user"); |
| 115 | +expect(fetchStep.getStatus()).toBe("SUCCEEDED"); |
| 116 | +``` |
| 117 | + |
| 118 | +See the [Testing SDK documentation](./packages/aws-durable-execution-sdk-js-testing/README.md) for more details. |
| 119 | + |
| 120 | +## 💬 Feedback & Support |
| 121 | + |
| 122 | +- **🐛 [Report a Bug](https://github.com/aws/aws-durable-execution-sdk-js/issues/new?template=bug_report.yml)** – Found something broken? Let us know |
| 123 | +- **💡 [Request a Feature](https://github.com/aws/aws-durable-execution-sdk-js/issues/new?template=feature_request.yml)** – Share ideas for improvements |
| 124 | +- **📖 [Documentation Issue](https://github.com/aws/aws-durable-execution-sdk-js/issues/new?template=documentation.yml)** – Report unclear or missing docs |
| 125 | +- **💬 [Discussions](https://github.com/aws/aws-durable-execution-sdk-js/discussions)** – Ask questions and connect with the community |
| 126 | + |
| 127 | +## 🤝 Contributing |
| 128 | + |
| 129 | +We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. |
| 130 | + |
| 131 | +## 🔒 Security |
| 132 | + |
| 133 | +See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for information about reporting security issues. |
| 134 | + |
| 135 | +## 📄 License |
| 136 | + |
| 137 | +This project is licensed under the Apache-2.0 License. See [LICENSE](LICENSE) for details. |
0 commit comments