{"id":19784830,"url":"https://github.com/vladholubiev/lambda-custom-authorizer-middleware","last_synced_at":"2025-10-19T08:28:08.165Z","repository":{"id":78248499,"uuid":"102524304","full_name":"vladholubiev/lambda-custom-authorizer-middleware","owner":"vladholubiev","description":"Lambda Custom Authorizer Middleware for using with AWS Serverless Express and Serverless Offline plugins","archived":false,"fork":false,"pushed_at":"2018-07-21T01:14:33.000Z","size":16,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-03T11:58:06.796Z","etag":null,"topics":["api-gateway","node-module","npm-package","serverless","serverless-offline"],"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/vladholubiev.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}},"created_at":"2017-09-05T19:59:42.000Z","updated_at":"2020-02-20T22:04:55.000Z","dependencies_parsed_at":"2023-02-27T15:01:44.193Z","dependency_job_id":null,"html_url":"https://github.com/vladholubiev/lambda-custom-authorizer-middleware","commit_stats":null,"previous_names":["vladholubiev/lambda-custom-authorizer-middleware","vladgolubev/lambda-custom-authorizer-middleware"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/vladholubiev/lambda-custom-authorizer-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladholubiev%2Flambda-custom-authorizer-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladholubiev%2Flambda-custom-authorizer-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladholubiev%2Flambda-custom-authorizer-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladholubiev%2Flambda-custom-authorizer-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vladholubiev","download_url":"https://codeload.github.com/vladholubiev/lambda-custom-authorizer-middleware/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vladholubiev%2Flambda-custom-authorizer-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260447679,"owners_count":23010546,"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":["api-gateway","node-module","npm-package","serverless","serverless-offline"],"created_at":"2024-11-12T06:12:50.724Z","updated_at":"2025-10-19T08:28:03.114Z","avatar_url":"https://github.com/vladholubiev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Lambda Local Middleware\n\n\u003e Lambda Custom Authorizer Middleware for using with AWS Serverless Express and Serverless Offline plugins\n\n[![npm](https://img.shields.io/npm/v/lambda-custom-authorizer-middleware.svg?maxAge=2592000)](https://www.npmjs.com/package/lambda-custom-authorizer-middleware)\n[![npm](https://img.shields.io/npm/dm/lambda-custom-authorizer-middleware.svg?maxAge=2592000)](https://github.com/vladgolubev/lambda-custom-authorizer-middleware)\n\n## Purpose\n\nLet's say you are using [aws-serverless-express](https://github.com/awslabs/aws-serverless-express).\nCool, you can write lambdas responding to API Gateway using favorite [express](https://github.com/expressjs/express).\n\nLet's say you are using [serverless-offline](https://github.com/dherault/serverless-offline) to simulate API Gateway for\nlocal development. Cool, now you can invoke your lambdas locally.\n\nLet's say you have custom lambda authorizers defined in your `serverless.yml` file like that:\n\n```yml\n  restAP:\n    handler: lib/handlers/rest-api.handler\n    events:\n      - http:\n          path: v1/{id}/create\n          method: put\n          integration: lambda-proxy\n          authorizer:\n            arn: arn:aws:lambda:us-east-1:123456789:function:myAuthorizerFunction\n            resultTtlInSeconds: 0\n```\n\nPretty soon you find [this issue](https://github.com/dherault/serverless-offline/issues/118) saying you cannot use custom non-local authorizers.\n\nAnd here it comes. With this package you can provide path on local file system to your custom authorizer function which isn't required to be inside the project.\n\n## Install\n\nNote, it's installed not in dev deps.\n\n```sh\n$ yarn add lambda-custom-authorizer-middleware\n```\n\n## Usage\n\nDue to the fact this package is meant to be used with [serverless-offline](https://github.com/dherault/serverless-offline)\nit relies on its environment variable `IS_OFFLINE` to switch on using local Lambda function.\n\nAnd as for now, it's limited to 1 kind of authorizer function per project.\n\n## API\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n### customLocalLambdaAuthorizer\n\nExpress middleware function constructor to execute local lambda function\nas a custom authorizer and attach request context to `req` object\nas `req.apiGateway.event.requestContext.authorizer` (as for usage with `aws-serverless-exporess` npm package)\n\n**Parameters**\n\n-   `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Configuration object (optional, default `{}`)\n    -   `options.identitySourceHeader` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of HTTP header where auth token is located (optional, default `authorization`)\n    -   `options.localAuthorizer` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Local authorizer function configuration object (optional, default `{}`)\n        -   `options.localAuthorizer.handlerPath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path on local file system to the function\n        -   `options.localAuthorizer.handlerName` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the exported function in provided path\n        -   `options.handlerPath`\n        -   `options.handlerName`\n\n**Examples**\n\n```javascript\nimport express from 'express';\nimport awsSlsExpressMiddleware from 'aws-serverless-express/middleware';\nimport {customLocalLambdaAuthorizer} from 'lambda-custom-authorizer-middleware';\n\nconst app = express();\n\napp.use(awsSlsExpressMiddleware.eventContext());\napp.use(customLocalLambdaAuthorizer({ // Make sure to add after 'awsSlsExpressMiddleware'\n localAuthorizer: {\n   handlerPath: '../other-project/lambda/auth',\n   handlerName: 'handler'\n }\n}));\n\napp.get('/', (req, res) =\u003e res.json(req.apiGateway.event.requestContext.authorizer));\n```\n\n-   Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** Throws when config is not provided\n\nReturns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Express middleware function. Works only when IS_OFFLINE env var is set.\n\n## Development\n\n### Debug\n\nThis package uses [debug](https://github.com/visionmedia/debug) library,\nso set environment variable like that to see the logs.\n\n```sh\nDEBUG=lambda-custom-authorizer-middleware sls offline start\n```\n\n### Lint\n\n```sh\n$ yarn lint\n```\n\n### Build\n\n```sh\n$ yarn build\n```\n\n### Docs\n\n```sh\n$ yarn docs\n```\n\n### Tests\n\n```sh\n$ yarn test\n```\n\n### Coverage\n\n```sh\n$ yarn coverage\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladholubiev%2Flambda-custom-authorizer-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvladholubiev%2Flambda-custom-authorizer-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvladholubiev%2Flambda-custom-authorizer-middleware/lists"}