{"id":15061712,"url":"https://github.com/jorgevrgs/fastify-aws-powertools","last_synced_at":"2026-01-21T18:36:31.943Z","repository":{"id":59943361,"uuid":"539704556","full_name":"jorgevrgs/fastify-aws-powertools","owner":"jorgevrgs","description":"Fastify plugin to use AWS Lambda Powertools for Typescript","archived":false,"fork":false,"pushed_at":"2025-09-17T14:46:43.000Z","size":651,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-19T22:35:11.497Z","etag":null,"topics":["aws-lambda","aws-lambda-node","aws-powertools","aws-xray","fastify","fastify-plugin"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jorgevrgs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-09-21T22:19:11.000Z","updated_at":"2025-09-17T14:46:01.000Z","dependencies_parsed_at":"2024-08-25T20:50:32.768Z","dependency_job_id":"65e8f2b1-81d2-406d-87c4-4b0d752f5a1a","html_url":"https://github.com/jorgevrgs/fastify-aws-powertools","commit_stats":{"total_commits":37,"total_committers":2,"mean_commits":18.5,"dds":"0.027027027027026973","last_synced_commit":"e0257f7f446c1d1098ad0e902231c94f74c57b81"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/jorgevrgs/fastify-aws-powertools","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Ffastify-aws-powertools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Ffastify-aws-powertools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Ffastify-aws-powertools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Ffastify-aws-powertools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jorgevrgs","download_url":"https://codeload.github.com/jorgevrgs/fastify-aws-powertools/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jorgevrgs%2Ffastify-aws-powertools/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28639393,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T18:04:35.752Z","status":"ssl_error","status_checked_at":"2026-01-21T18:03:55.054Z","response_time":86,"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","aws-lambda-node","aws-powertools","aws-xray","fastify","fastify-plugin"],"created_at":"2024-09-24T23:24:02.290Z","updated_at":"2026-01-21T18:36:31.938Z","avatar_url":"https://github.com/jorgevrgs.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-aws-powertools\n\n[![NPM Version](https://img.shields.io/npm/v/fastify-aws-powertools.svg)](https://npmjs.org/package/fastify-aws-powertools) [![CI](https://github.com/jorgevrgs/fastify-aws-powertools/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/jorgevrgs/fastify-aws-powertools/actions/workflows/tests.yml)\n\n## Introduction\n\nImplementation of a Fastify plugin of [AWS Lambda Powertools for Typescript](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/) to take advantage of Logger, Metrics, and Tracer services for [AWS Lambda](https://aws.amazon.com/lambda/). Inspired by Middy middleware created by AWS Lambda Powertools team.\n\n## Versions\n\n\u003c!-- a table to show v0 is for fastify@4 and v5 is for fastify@5 --\u003e\n| fastify-aws-powertools | fastify | Node.js |\n|------------------------|---------|---------|\n| v0.x.x                 | 4.x.x   | 18.x, 20.x, 22.x |\n| v5.x.x                 | 5.x.x   | 20.x, 22.x, 24.x |\n\n## Getting Started\n\nInstall the dependency:\n\n```sh\nnpm i fastify-aws-powertools\n```\n\nAdd peer dependencies (if there are not installed yet):\n\n```sh\nnpm i fastify @fastify/aws-lambda\n```\n\nConfigure the plugin:\n\n```typescript\nimport fastifyAwsPowertool from 'fastify-aws-powertools';\nimport type { FastifyAwsPowertoolsOptions } from 'fastify-aws-powertools';\nimport type { FastifyASyncPlugin } from 'fastify';\n\nexport const plugin: FastifyASyncPlugin = async (fastify) =\u003e {\n  const options: FastifyAwsPowertoolsOptions = {\n    loggerOptions: {\n      logEvent: true,\n      clearState: true,\n    },\n    metricsOptions: {\n      captureColdStartMetric: true,\n    },\n    tracerOptions: {\n      captureResponse: true,\n    },\n  };\n  fastify.register(fastifyAwsPowertool, options);\n};\n```\n\nAlso, available each plugin separately:\n\n```typescript\nimport { fastifyAwsPowertoolsLogger } from 'fastify-aws-powertools';\nimport type { FastifyAwsPowertoolsOptions } from 'fastify-aws-powertools';\nimport type { FastifyASyncPlugin } from 'fastify';\n\nexport const plugin: FastifyASyncPlugin = async (fastify) =\u003e {\n  const options: FastifyAwsPowertoolsOptions = {\n    loggerOptions: {\n      logEvent: true,\n      clearState: true,\n    }\n  };\n  fastify.register(fastifyAwsPowertoolsLogger, options);\n};\n```\n\n### Dependencies\n\nInstall and configure `@fastify/aws-lambda` to use this plugin. See [@fastify/aws-lambda](https://github.com/fastify/aws-lambda-fastify).\n\n## Options\n\nLogger, Metrics, and Tracer instances will be automatically provided if either `(logger|metrics|tracer)` or `(logger|metrics|tracer)InstanceOptions` are provided.\n\n### Logger Plugin\n\n| Property              | Description                                                                                                             | Default     |\n| --------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------- |\n| logger                | Logger instance, otherwise provide loggerInstanceOptions | `undefined` |\n| loggerOptions  | `{logEvent?: boolean; resetKeys?: boolean;}`                                                                           | `undefined` |\n| loggerInstanceOptions  | See [ConstructorOptions](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/logger/src/types/Logger.ts#L180) | `undefined` |\n\n### Metrics Plugin\n\n| Property              | Description                                                                                                             | Default     |\n| --------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------- |\n| metrics               | Metrics instance, otherwise provide metricsInstanceOptions | `undefined` |\n| metricsOptions | `{throwOnEmptyMetrics?: boolean; defaultDimensions?: Record\u003c[key: string]: string\u003e; captureColdStartMetric?: boolean;}` | `undefined` |\n| metricsInstanceOptions | See [MetricsOptions](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/metrics/src/types/Metrics.ts#L9) | `undefined` |\n\n### Tracer Plugin\n\n| Property              | Description                                                                                                             | Default     |\n| --------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------- |\n| tracer                | Tracer instance, otherwise provide tracerInstanceOptions | `undefined` |\n| tracerOptions  | `{captureResponse?: boolean;}`                                                                                          | `undefined` |\n| tracerInstanceOptions  | See [TracerOptions](https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/tracer/src/types/Tracer.ts#L22) | `undefined` |\n\n\n### PowerTools Plugin\n\nUse `fastifyAwsPowertoolsPlugin` if you want to use all the plugins.\n\n## Example\n\nSimple example using all the plugins:\n\n```typescript\n// index.ts\nimport fastify from 'fastify';\nimport awsLambdaFastify from '@fastify/aws-lambda';\nimport { MetricUnits } from '@aws-lambda-powertools/metrics';\nimport fastifyAwsPowertool, {\n  type FastifyAwsPowertoolsOptions,\n} from 'fastify-aws-powertools';\n\nconst server = fastify({\n  logger: false,\n});\n\nserver.register(fastifyAwsPowertool);\n\nserver.get('/', async (request, reply) =\u003e {\n  request.tracer.putAnnotation('successfulBooking', true);\n  request.logger.info('This is a log with an extra variable', {\n    foo: 'bar',\n  });\n  request.metrics.addMetric('successfulBooking', MetricUnits.Count, 1);\n  request.metrics.addMetadata(\n    'bookingId',\n    '7051cd10-6283-11ec-90d6-0242ac120003',\n  );\n  request.metrics.publishStoredMetrics();\n\n  return 'Hello world!';\n});\n\nconst proxy = awsLambdaFastify(server);\n\nexport const handler = async (event: any, context: any) =\u003e\n  proxy(event, context);\n```\n\nAdditional examples can be found in the [examples](./examples) folder.\n\n```typescript\nimport fastifyAwsPowertoolsPlugin, { type FastifyAwsPowertoolsOptions, Logger as FastifyLogger } from 'fastify-aws-powertools';\nimport { Logger } from '@aws-lambda-powertools/logger';\nimport { Metrics } from '@aws-lambda-powertools/metrics';\nimport { Tracer } from '@aws-lambda-powertools/tracer';\nimport { Fastify, type FastifyASyncPlugin } from 'fastify';\n\n\nconst serviceName = 'my-service';\n\nconst logger = new Logger({\n    serviceName,\n  });\n\nconst metrics = new Metrics({\n  serviceName,\n  namespace: serviceName,\n});\n\nconst tracer = new Tracer({\n  serviceName,\n  captureHTTPsRequests: true,\n});\n\ntracer.provider.setLogger(logger);\n\nexport const myPlugin: FastifyASyncPlugin = async (fastify) =\u003e {\n\n  const options: FastifyAwsPowertoolsOptions = {\n    logger,\n    metrics,\n    tracer,\n    loggerOptions: {\n      logEvent: true,\n      clearState: true,\n    },\n    metricsOptions: {\n      captureColdStartMetric: true,\n    },\n    tracerOptions: {\n      captureResponse: true,\n    },\n  };\n  fastify.register(fastifyAwsPowertoolsPlugin, options);\n};\n\nconst logger = new FastifyLogger({\n  serviceName\n});\n\nconst app = Fastify({ logger });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgevrgs%2Ffastify-aws-powertools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjorgevrgs%2Ffastify-aws-powertools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjorgevrgs%2Ffastify-aws-powertools/lists"}