{"id":15233425,"url":"https://github.com/willfarrell/middy-rds","last_synced_at":"2025-10-31T00:38:38.222Z","repository":{"id":49131213,"uuid":"328493018","full_name":"willfarrell/middy-rds","owner":"willfarrell","description":"Middy middleware for creating a db connection using knex","archived":false,"fork":false,"pushed_at":"2024-07-14T21:31:04.000Z","size":694,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-02T05:03:39.993Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/willfarrell.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":"2021-01-10T22:33:40.000Z","updated_at":"2025-02-25T08:25:35.000Z","dependencies_parsed_at":"2024-06-21T05:43:33.233Z","dependency_job_id":"7dd0ba45-0b65-4bde-9df7-adbf5da74bc7","html_url":"https://github.com/willfarrell/middy-rds","commit_stats":{"total_commits":30,"total_committers":4,"mean_commits":7.5,"dds":"0.33333333333333337","last_synced_commit":"2e5834996ec68b8d69221ca45d9eaa0494aee162"},"previous_names":[],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fmiddy-rds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fmiddy-rds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fmiddy-rds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willfarrell%2Fmiddy-rds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willfarrell","download_url":"https://codeload.github.com/willfarrell/middy-rds/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248162960,"owners_count":21057842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-09-29T05:08:50.565Z","updated_at":"2025-10-31T00:38:33.184Z","avatar_url":"https://github.com/willfarrell.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Middy RDS Middleware\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg alt=\"Middy logo\" src=\"https://raw.githubusercontent.com/middyjs/middy/master/docs/img/middy-logo.png\"/\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cp\u003e\u003cstrong\u003eSimple database manager for the middy framework\u003c/strong\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cp\u003e\n  \u003ca href=\"http://badge.fury.io/js/%40willfarrell%2Fmiddy-rds\"\u003e\n    \u003cimg src=\"https://badge.fury.io/js/%40willfarrell%2Fmiddy-rds.svg\" alt=\"npm version\" style=\"max-width:100%;\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://snyk.io/test/github/willfarrell/middy-rds\"\u003e\n    \u003cimg src=\"https://snyk.io/test/github/willfarrell/middy-rds/badge.svg\" alt=\"Known Vulnerabilities\" data-canonical-src=\"https://snyk.io/test/github/willfarrell/middy-rds\" style=\"max-width:100%;\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://standardjs.com/\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/code_style-standard-brightgreen.svg\" alt=\"Standard Code Style\"  style=\"max-width:100%;\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://gitter.im/middyjs/Lobby\"\u003e\n    \u003cimg src=\"https://badges.gitter.im/gitterHQ/gitter.svg\" alt=\"Chat on Gitter\"  style=\"max-width:100%;\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003c/div\u003e\n\nRDS provides seamless connection with database of your choice.\n\nAfter initialization your database connection is accessible under:\n\n```javascript\nmiddy((event, context) =\u003e {\n  const { sql } = context\n})\n```\n\nMind that if you use knex you will also need driver of your choice ([check docs](http://knexjs.org/#Installation-node)), for PostgreSQL that would be:\n\n```\nyarn add {pg,postgres}\n// or\nnpm install {pg,postgres}\n```\n\n## Install\n\nTo install this middleware you can use NPM:\n\n```bash\nnpm install --save middy-rds\nnpm install --save-dev @aws-sdk/rds-signer\n```\n\nRequires: @middy/core:\u003e=4.0.0\n\n## Options\n\n- `client` (function) (required): client that you want to use when connecting to database of your choice. Designed to be used by knex.js. However, as long as your client is run as client(config), you can use other tools.\n- `config` (object) (required): configuration object passed as is to client (knex.js recommended), for more details check [knex documentation](http://knexjs.org/#Installation-client)\n- `internalData` (object) (optional): Pull values from middy internal storage into `config.connection` object.\n- `cacheKey` (string) (default `rds`): Cache key for the fetched data responses. Must be unique across all middleware.\n- `cachePasswordKey` (string) (default `rds`):Cache key for the fetched data response related to the password. Must match the `cacheKey` for the middleware that stores it.\n- `cacheExpiry` (number) (default `-1`): How long fetch data responses should be cached for. `-1`: cache forever, `0`: never cache, `n`: cache for n ms.\n\n**Note:**\n\n- `config.connection` defaults to:\n\n```javascript\n{\n  ssl: {\n    rejectUnauthorized: true,\n    ca, // readFile(process.env.NODE_EXTRA_CA_CERTS)\n    checkServerIdentity: (host, cert) =\u003e {\n      const error = tls.checkServerIdentity(host, cert)\n      if (error \u0026\u0026 !cert.subject.CN.endsWith('.rds.amazonaws.com')) {\n         return error\n      }\n    }\n  }\n}\n```\n\nIf your lambda is timing out, likely your database connections are keeping the event loop open. Check out [do-not-wait-for-empty-event-loop](https://github.com/middyjs/middy/tree/master/packages/do-not-wait-for-empty-event-loop) middleware to resolve this.\n\n## Sample usage\n\nMinimal configuration\n\n### pg\n\n```javascript\nimport rdsMiddleware from 'middy-rds/pg'\n\nimport capturePostgres from 'aws-xray-sdk-postgres'\nimport pgClient from 'pg'\n\nconst pg = capturePostgres(pgClient)\n\nconst handler = middy(async (event, context) =\u003e {\n  const { sql } = context\n  const records = await sql.select('*').from('my_table')\n  console.log(records)\n}).use(\n  rdsMiddleware({\n    client: pg.Pool,\n    config: {\n      host: '*.ca-central-1.rds.amazonaws.com',\n      user: 'iam_role',\n      database: 'postgres',\n      application_name: process.env.AWS_LAMBDA_FUNCTION_NAME\n    }\n  })\n)\n```\n\n### knex\n\n```javascript\nimport rdsMiddleware from 'middy-rds/knex'\nimport knex from 'knex'\n\nimport capturePostgres from 'aws-xray-sdk-postgres'\nimport pgClient from 'pg'\n\nconst pg = capturePostgres(pgClient)\n\nconst handler = middy(async (event, context) =\u003e {\n  const { sql } = context\n  const records = await sql.select('*').from('my_table')\n  console.log(records)\n}).use(\n  rdsMiddleware({\n    client: knex,\n    config: {\n      client: 'pg',\n      connection: {\n        host: '*.ca-central-1.rds.amazonaws.com',\n        user: 'iam_role',\n        database: 'postgres',\n        port: 5432,\n        application_name: process.env.AWS_LAMBDA_FUNCTION_NAME\n      }\n    }\n  })\n)\n```\n\n### postgres\n\n```javascript\nimport rdsMiddleware from 'middy-rds/postgres'\n\nimport postgresClient from 'postgres'\n\nconst handler = middy(async (event, context) =\u003e {\n  const { sql } = context\n  const records = await sql`SELECT * FROM my_table`\n  console.log(records)\n}).use(\n  rdsMiddleware({\n    client: postgresClient,\n    config: {\n      host: '*.ca-central-1.rds.amazonaws.com',\n      user: 'iam_role',\n      database: 'postgres',\n      connection: {\n        application_name: process.env.AWS_LAMBDA_FUNCTION_NAME\n      }\n    }\n  })\n)\n```\n\n## Middy documentation and examples\n\nFor more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).\n\n## Contributing\n\nEveryone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).\n\n## License\n\nLicensed under [MIT License](LICENSE). Copyright (c) 2017-2022 will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).\n\n\u003ca href=\"https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large\"\u003e\n  \u003cimg src=\"https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large\" alt=\"FOSSA Status\"  style=\"max-width:100%;\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fmiddy-rds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillfarrell%2Fmiddy-rds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillfarrell%2Fmiddy-rds/lists"}