|
| 1 | +# Lambda Utilities Project Instructions |
| 2 | + |
| 3 | +This project contains a set of utilities and helper functions designed to streamline the development of AWS Lambda functions using TypeScript. The utilities cover common tasks such as input validation, response formatting, error handling, and logging. The project is packaged and published as an npm package for easy integration into other Lambda projects. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Technology Stack |
| 8 | + |
| 9 | +Each pattern project uses the following technology stack: |
| 10 | + |
| 11 | +- **Language:** TypeScript |
| 12 | +- **Platform:** AWS Lambda |
| 13 | +- **Runtime:** Node.js 24.x |
| 14 | +- **AWS SDK:** v3 (modular packages) |
| 15 | +- **Testing:** Jest |
| 16 | +- **Linting/Formatting:** ESLint + Prettier |
| 17 | +- **Validation:** Zod |
| 18 | +- **Logging:** Pino + Pino-Lambda |
| 19 | +- **Package Manager:** npm |
| 20 | +- **Package Bundler:** rollup |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Pattern Project Structure |
| 25 | + |
| 26 | +Each pattern project follows a consistent directory and file structure to promote maintainability and scalability. Below is an example structure: |
| 27 | + |
| 28 | +``` |
| 29 | +/docs # Project documentation |
| 30 | + README.md # Documentation table of contents |
| 31 | +
|
| 32 | +/src |
| 33 | + /logging |
| 34 | + logger.ts # Logger utility using Pino |
| 35 | + logger.test.ts # Unit tests for logger |
| 36 | + /clients |
| 37 | + dynamodb-client.ts # AWS SDK client for DynamoDB |
| 38 | + dynamodb-client.test.ts # Unit tests for DynamoDB client |
| 39 | + lambda-client.ts # AWS SDK client for Lambda |
| 40 | + lambda-client.test.ts # Unit tests for Lambda client |
| 41 | + /validation |
| 42 | + config.ts # Configuration validation with Zod |
| 43 | + config.test.ts # Unit tests for config |
| 44 | + validator.ts # Generic validator helpers |
| 45 | + validator.test.ts # Unit tests for validator |
| 46 | + /responses |
| 47 | + apigateway-response.ts # Standard API response helpers |
| 48 | + apigateway-response.test.ts # Unit tests for API response helpers |
| 49 | +.editorconfig # Editor config |
| 50 | +.gitignore # Git ignore rules |
| 51 | +.nvmrc # Node version manager config |
| 52 | +.prettierrc # Prettier config |
| 53 | +eslint.config.mjs # ESLint config |
| 54 | +jest.config.ts # App Jest config |
| 55 | +jest.setup.ts # App Jest setup |
| 56 | +package.json # App NPM package config |
| 57 | +README.md # Project README |
| 58 | +tsconfig.json # Project TypeScript config |
| 59 | +``` |
| 60 | + |
| 61 | +--- |
| 62 | + |
| 63 | +## Source Code Guidelines |
| 64 | + |
| 65 | +Each pattern project follows best practices for source code organization, naming conventions, and coding standards. Below are the key guidelines: |
| 66 | + |
| 67 | +- Use **TypeScript** for all source and infrastructure code. |
| 68 | +- Use arrow functions for defining functions. |
| 69 | +- Use path aliases for cleaner imports (e.g., `@utils`, `@models`). |
| 70 | +- Organize import statements: external packages first, then internal modules. |
| 71 | +- Use async/await for asynchronous operations. |
| 72 | +- Document functions and modules with JSDoc comments. |
| 73 | + |
| 74 | +### Source Code Commands & Scripts |
| 75 | + |
| 76 | +- Use `npm run build` to compile TypeScript. |
| 77 | +- Use `npm run test` to run tests. |
| 78 | +- Use `npm run test:coverage` to run tests with coverage report. |
| 79 | +- Use `npm run lint` to run ESLint. |
| 80 | +- Use `npm run lint:fix` to fix ESLint issues. |
| 81 | +- Use `npm run format` to run Prettier to format code. |
| 82 | +- Use `npm run format:check` to check code formatting with Prettier. |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Unit Testing Guidelines |
| 87 | + |
| 88 | +Each pattern project includes comprehensive unit tests for both application and infrastructure code. Below are the key guidelines for writing unit tests: |
| 89 | + |
| 90 | +- Use the **Jest** testing framework. |
| 91 | +- Place test files next to the source file, with `.test.ts` suffix. |
| 92 | +- Use `describe` and `it` blocks for organization. |
| 93 | +- Use `beforeEach` for setup and `afterEach` for cleanup. |
| 94 | +- Use `expect` assertions for results. |
| 95 | +- Mock dependencies to isolate the component under test. |
| 96 | +- Mock external calls (e.g., AWS SDK, databases). |
| 97 | +- Structure your tests using the Arrange-Act-Assert pattern: |
| 98 | + - **Arrange:** Set up the test environment, including any necessary mocks and test data. |
| 99 | + - **Act:** Execute the function or service being tested. |
| 100 | + - **Assert:** Verify that the results are as expected. |
| 101 | + - Add comments to separate these sections for clarity. |
0 commit comments