{"id":25016588,"url":"https://github.com/viccon/aws-lambda-express-middlewares","last_synced_at":"2025-10-03T23:07:15.860Z","repository":{"id":143869709,"uuid":"338289961","full_name":"viccon/aws-lambda-express-middlewares","owner":"viccon","description":"A lightweight alternative to step functions. Create middlewares with an express-like API.","archived":false,"fork":false,"pushed_at":"2021-06-24T14:40:23.000Z","size":101,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T07:06:27.847Z","etag":null,"topics":["lambda-functions","middleware-functions","middlewares","typescript"],"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/viccon.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}},"created_at":"2021-02-12T10:43:07.000Z","updated_at":"2022-08-24T09:31:45.000Z","dependencies_parsed_at":"2024-02-01T01:15:11.679Z","dependency_job_id":null,"html_url":"https://github.com/viccon/aws-lambda-express-middlewares","commit_stats":null,"previous_names":["creativecreature/lambda-express-middlewares","viccon/aws-lambda-express-middlewares"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viccon%2Faws-lambda-express-middlewares","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viccon%2Faws-lambda-express-middlewares/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viccon%2Faws-lambda-express-middlewares/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/viccon%2Faws-lambda-express-middlewares/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/viccon","download_url":"https://codeload.github.com/viccon/aws-lambda-express-middlewares/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246290583,"owners_count":20753724,"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":["lambda-functions","middleware-functions","middlewares","typescript"],"created_at":"2025-02-05T09:49:43.445Z","updated_at":"2025-10-03T23:07:10.820Z","avatar_url":"https://github.com/viccon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambda express middlewares\nThis package allows you to create reusable middleware functions, with a function\nsignature that is similar to express. You are then able to order them however you\nwant. The middlewares are executed left to right, the last one will invoke your\nhandler.\n\nThis package has no external dependencies. Therefore, it wont add any bloat to your\nlambda functions.\n\n## Examples\nHere are some examples on how this package can be used. The middlewares are only\nfor demo purposes.\n\n#### Extend your lambda context with additional data (like a custom user object):\n\n```js\nimport { withMiddlewares } from 'lambda-express-middlewares'\n\nconst authenticate = async (token) =\u003e {\n  const user = await authenticaitonService.getUser(token)\n  return user\n}\n\n// Create a middleware for adding a custom user object to your lambda context.\nconst authMiddleware = async (event, context, next) =\u003e {\n  const user = await authenticate()\n  const userContext = { ...context, user }\n  return await next(event, userContext)\n}\n\n// Create a middleware that relies on the user being there, and fetches additional information.\nconst orderMiddleware = async (event, context, next) =\u003e {\n  const { user } = context\n  const orders = await orderService.getOrders(user.email)\n  const orderContext = { ...context, orders }\n  return await next(event, orderContext)\n}\n\n// Your regular lambda handler.\nconst apiHandler = async (event, context) =\u003e {\n  const { user, orders } = context\n  // ... your specific logic\n\n  return { statusCode: 200, body: JSON.stringify({ message: 'success' }) }\n}\n\n// Export your handler with middlewares.\nexport const handler = withMiddlewares([authMiddleware, orderMiddleware], apiHandler)\n```\n\n\n#### Create a reusable middleware for validating your requests:\n\n```js\nimport { withMiddlewares } from 'lambda-express-middlewares'\n\nconst orderRegex = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i)\n\n// Your custom middleware, takes in an additional next function, similar to express.\nconst validateOrderMiddleware = async (event, context, next) =\u003e {\n  const orderId = event.pathParameters.orderId\n\n  if !(orderRegex.test(orderId)) {\n    // Validation failed, you can therefore exit early by returning and not invoking the *next* function.\n    return { statusCode: 400, body: JSON.stringify(null) }\n  }\n\n  // Validation passed, invoke the handler!\n  return await next(event, context)\n}\n\n// Your regular lambda handler.\nconst apiHandler = async (event, context) =\u003e {\n  // At this point you know that the orderId has been validated\n  const orderId = event.pathParameters.orderId\n  // ... your specific logic\n\n  return { statusCode: 200, body: JSON.stringify({ message: 'success' }) }\n}\n\n// Export your handler with middlewares.\nexport const handler = withMiddlewares([validateOrderMiddleware], apiHandler)\n```\n\n\n#### Your middlewares can wrap the handler, or other middlewares, to do cleanup\n\n```js\nimport { withMiddlewares } from 'lambda-express-middlewares'\n\n// Your custom middleware, takes in an additional next function, similar to express.\nconst cleanupMiddleware = async (event, context, next) =\u003e {\n  try {\n    const res = await next(event, context)\n    return res\n  } catch (e) {\n    console.log()\n    return { statusCode: 500, body: { message: 'e.message' } }\n  } finally {\n    // Some code to cleanup\n  }\n}\n\n// Your regular lambda handler.\nconst apiHandler = async (event, context) =\u003e {\n  const result = await someService(event)\n  return { statusCode: 200, body: JSON.stringify({ message: 'success' }) }\n}\n\n// Export your handler with middlewares.\nexport const handler = withMiddlewares([validateOrderMiddleware], apiHandler)\n```\n\n\n## Typescript\nFor examples in *typescript*, check out the test file in this project. There\nyou will find some examples on how to type your middleware functions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviccon%2Faws-lambda-express-middlewares","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviccon%2Faws-lambda-express-middlewares","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviccon%2Faws-lambda-express-middlewares/lists"}