{"id":39782247,"url":"https://github.com/comicrelief/lambda-wrapper","last_synced_at":"2026-01-18T12:04:20.622Z","repository":{"id":38310262,"uuid":"143699035","full_name":"comicrelief/lambda-wrapper","owner":"comicrelief","description":"Lambda Wrapper for AWS NodeJS Projects","archived":false,"fork":false,"pushed_at":"2025-09-16T09:30:51.000Z","size":2073,"stargazers_count":19,"open_issues_count":26,"forks_count":0,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-10-19T15:36:26.789Z","etag":null,"topics":["aws-lambda","serverless"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/comicrelief.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2018-08-06T08:30:09.000Z","updated_at":"2025-01-29T14:24:37.000Z","dependencies_parsed_at":"2023-10-16T19:14:54.458Z","dependency_job_id":"5acff1ef-38e9-47c4-bcda-32c5f69d4eb4","html_url":"https://github.com/comicrelief/lambda-wrapper","commit_stats":{"total_commits":261,"total_committers":15,"mean_commits":17.4,"dds":0.6091954022988506,"last_synced_commit":"cc7bdd2ba6ed7b5cc9eb6c831c348065e4f4823b"},"previous_names":[],"tags_count":123,"template":false,"template_full_name":null,"purl":"pkg:github/comicrelief/lambda-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comicrelief%2Flambda-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comicrelief%2Flambda-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comicrelief%2Flambda-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comicrelief%2Flambda-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/comicrelief","download_url":"https://codeload.github.com/comicrelief/lambda-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comicrelief%2Flambda-wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28535349,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T10:13:46.436Z","status":"ssl_error","status_checked_at":"2026-01-18T10:13:11.045Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","serverless"],"created_at":"2026-01-18T12:04:20.096Z","updated_at":"2026-01-18T12:04:20.609Z","avatar_url":"https://github.com/comicrelief.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambda Wrapper\n\n![GitHub Actions](https://github.com/comicrelief/lambda-wrapper/actions/workflows/main.yml/badge.svg)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![semantic-release](https://badge.fury.io/js/%40comicrelief%2Flambda-wrapper.svg)](https://www.npmjs.com/package/@comicrelief/lambda-wrapper)\n\nWhen writing Serverless applications, we have found ourselves replicating a lot of boilerplate code to do basic actions, such as reading request data or sending messages to SQS. The aim of this package is to provide a wrapper for our Lambda functions, to provide some level of dependency and configuration injection and to reduce time spent on project setup.\n\nIf you're coming from v1 and updating to v2, check out the [v2 migration guide](docs/migration/v2.md).\n\n## Getting started\n\nInstall via npm or Yarn:\n\n```bash\nnpm i @comicrelief/lambda-wrapper\n# or\nyarn add @comicrelief/lambda-wrapper\n```\n\nYou can then wrap your Lambda handler functions like this:\n\n```ts\n// src/action/Hello.ts\nimport lambdaWrapper, {\n  ResponseModel,\n  RequestService,\n} from '@comicrelief/lambda-wrapper';\n\nexport default lambdaWrapper.wrap(async (di) =\u003e {\n  const request = di.get(RequestService);\n  return ResponseModel.generate(\n    {},\n    200,\n    `hello ${request.get('name', 'nobody')}`,\n  );\n});\n```\n\nHere we've used the default export `lambdaWrapper` which is a preconfigured instance that can be used out of the box. You'll likely want to add your own dependencies and service config using the `configure` method:\n\n```ts\n// src/config/LambdaWrapper.ts\nimport lambdaWrapper from '@comicrelief/lambda-wrapper';\n\nexport default lambdaWrapper.configure({\n  // your config goes here\n});\n```\n\n`configure` returns a new Lambda Wrapper instance with the given configuration. You'll want to export it and then use this when wrapping your handler functions.\n\nRead the next section to see what goes inside the config object!\n\nIf you want to start from scratch without the built-in dependencies, you can use the `LambdaWrapper` constructor directly.\n\n```ts\n// src/config/LambdaWrapper.ts\nimport { LambdaWrapper } from '@comicrelief/lambda-wrapper';\n\nexport default new LambdaWrapper({\n  // your config goes here\n});\n```\n\n## Dependencies\n\nLambda Wrapper comes with some commonly used dependencies built in:\n\n- [HTTPService](docs/services/HTTPService.md)\n- [LoggerService](docs/services/LoggerService.md)\n- [RequestService](docs/services/RequestService.md)\n- [SQSService](docs/services/SQSService.md)\n- [TimerService](docs/services/TimerService.md)\n\nAccess these via dependency injection. You've already seen an example of this where we got `RequestService`. Pass the dependency class to `di.get()` to get its instance:\n\n```ts\nexport default lambdaWrapper.wrap(async (di) =\u003e {\n  const request = di.get(RequestService);\n  const sqs = di.get(SQSService);\n  // ...\n});\n```\n\nTo add your own dependencies, first extend `DependencyAwareClass`.\n\n```ts\n// src/services/MyService.ts\nimport { DependencyAwareClass } from '@comicrelief/lambda-wrapper';\n\nexport default class MyService extends DependencyAwareClass {\n  doSomething() {\n    // ...\n  }\n}\n```\n\nIf you need to override the constructor, it must take a `DependencyInjection` instance and pass it to `super`.\n\n```ts\nexport default class MyService extends DependencyAwareClass {\n  constructor(di: DependencyInjection) {\n    super(di);\n    // now do your other constructor stuff\n  }\n}\n```\n\nThen add it to your Lambda Wrapper configuration in the `dependencies` key.\n\n```ts\n// src/config/LambdaWrapper.ts\nimport lambdaWrapper from '@comicrelief/lambda-wrapper';\n\nimport MyService from '@/src/services/MyService';\n\nexport default lambdaWrapper.configure({\n  dependencies: {\n    MyService,\n  },\n});\n```\n\nNow you can use it inside your handler functions and other dependencies!\n\n```ts\n// src/action/DoSomething.ts\nimport lambdaWrapper from '@/src/config/LambdaWrapper';\nimport MyService from '@/src/services/MyService';\n\nexport default lambdaWrapper.wrap(async (di) =\u003e {\n  di.get(MyService).doSomething();\n});\n```\n\n## Service config\n\nSome dependencies need their own config. This goes in per-service keys within your Lambda Wrapper config. For an example, see [SQSService](docs/services/SQSService.md) which uses the `sqs` key.\n\n```ts\nexport default lambdaWrapper.configure({\n  dependencies: {\n    // your dependencies\n  },\n  sqs: {\n    // your SQSService config\n  },\n  // ... other configs ...\n});\n```\n\nTo use config with your own dependencies, you need to do three things:\n\n1. Define the key and type of your config object.\n\n   Using `SQSService` as an example, we have the `sqs` key which has the `SQSServiceConfig` type:\n\n   ```ts\n   export interface SQSServiceConfig {\n     queues?: Record\u003cstring, string\u003e;\n     queueConsumers?: Record\u003cstring, string\u003e;\n   }\n   ```\n\n2. Define a type that can be applied to a Lambda Wrapper config.\n\n   This simply combines the key and type defined in step 1. Conventionally we name these `With...` types.\n\n   ```ts\n   export interface WithSQSServiceConfig {\n     sqs?: SQSServiceConfig;\n   }\n   ```\n\n   In the case of `SQSService`, the `sqs` key is optional because this dependency is included by default and not all applications need it. If your dependency requires config in order to work, you can make this a required key.\n\n3. In your dependency constructor, cast the config to this type.\n\n   ```ts\n   export default class SQSService extends DependencyAwareClass {\n     constructor(di: DependencyInjection) {\n       super(di);\n\n       const config = (this.di.config as WithSQSServiceConfig).sqs;\n       // Bear in mind that because the `sqs` key is optional, the type of\n       // `config` will be `SQSServiceConfig | undefined`. Take care when\n       // accessing its properties! You can use optional chaining:\n       const queues = config?.queues || {};\n       // ...\n     }\n   }\n   ```\n\nWhen you go to configure your Lambda Wrapper, you can now include your dependency's config type in the generic for `configure` to get IntelliSense completions and type checking for your config keys.\n\n```ts\nlambdaWrapper.configure\u003cWithSQSServiceConfig\u003e({\n  sqs: {\n    queues: 42 // Oops! This will be flagged as a type error by TypeScript\n  },\n});\n```\n\nYou can combine types for multiple dependencies if needed using `\u0026`:\n\n```ts\nlambdaWrapper.configure\u003cWithSQSServiceConfig \u0026 WithOtherServiceConfig\u003e({\n  sqs: {\n    // SQSService config\n  },\n  other: {\n    // OtherService config\n  },\n});\n```\n\n## Monitoring\n\nAt Comic Relief we use [Lumigo](https://lumigo.io/) for monitoring and observability of our deployed services. Lambda Wrapper includes the Lumigo tracer to allow us to tag traces with custom labels and metrics ([execution tags](https://docs.lumigo.io/docs/execution-tags)).\n\nLumigo integration works out-of-the-box with Lumigo's [auto-trace feature](https://docs.lumigo.io/docs/serverless-applications#automatic-instrumentation). If you prefer manual tracing, enable it by setting `LUMIGO_TRACER_TOKEN` in your Lambda environment variables.\n\nAnd if you don't use Lumigo, don't worry, their tracer will not be instantiated in your functions and no calls will be made to their servers unless `LUMIGO_TRACER_TOKEN` is set.\n\n## Notes\n\nLambda Wrapper's dependency injection relies on class names being preserved. If your build process includes minifying or uglifying your code, you'll need to disable these transformations.\n\nIn many of our projects we use `serverless-webpack` to bundle service code prior to deployment. To disable name mangling, set `optimization.minimize` to `false` in your webpack config:\n\n```js\n// webpack.config.js\nmodule.exports = {\n  // ...\n  optimization: {\n    minimize: false,\n  },\n```\n\n## Development\n\n### Testing\n\nRun `yarn test` to run the unit tests, and `yarn test:types` to run the type tests.\n\nWhen writing a bugfix, start by writing a test that reproduces the problem. It should fail with the current version of Lambda Wrapper, and pass once you've implemented the fix.\n\nWhen adding a feature, ensure it's covered by tests that adequately define its behaviour.\n\n### Linting\n\nRun `yarn lint` to check code style complies to our standard. Many problems can be auto-fixed using `yarn lint --fix`.\n\n### Releases\n\nRelease management is automated using [semantic-release](https://www.npmjs.com/package/semantic-release).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomicrelief%2Flambda-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomicrelief%2Flambda-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomicrelief%2Flambda-wrapper/lists"}