Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lambda-custom-authorizer-middleware

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-custom-authorizer-middleware

Adds support of custom lambda authorizers for local offline usage, e.g. with serverless-offlin

  • 1.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

AWS Lambda Local Middleware

Lambda Custom Authorizer Middleware for using with AWS Serverless Express and Serverless Offline plugins

npm npm

Purpose

Let's say you are using aws-serverless-express. Cool, you can write lambdas responding to API Gateway using favorite express.

Let's say you are using serverless-offline to simulate API Gateway for local development. Cool, now you can invoke your lambdas locally.

Let's say you have custom lambda authorizers defined in your serverless.yml file like that:

  restAP:
    handler: lib/handlers/rest-api.handler
    events:
      - http:
          path: v1/{id}/create
          method: put
          integration: lambda-proxy
          authorizer:
            arn: arn:aws:lambda:us-east-1:123456789:function:myAuthorizerFunction
            resultTtlInSeconds: 0

Pretty soon you find this issue saying you cannot use custom non-local authorizers.

And 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.

Install

$ yarn add lambda-custom-authorizer-middleware

API

customLocalLambdaAuthorizer

src/index.js:36-78

Express middleware function constructor to execute local lambda function as a custom authorizer and attach request context to req object as req.apiGateway.event.requestContext.authorizer (as for usage with aws-serverless-exporess npm package)

Parameters

  • options Object Configuration object (optional, default {})
    • options.identitySourceHeader String Name of HTTP header where auth token is located (optional, default authorization)
    • options.localAuthorizer Object Local authorizer function configuration object (optional, default {})
      • options.localAuthorizer.handlerPath String Path on local file system to the function
      • options.localAuthorizer.handlerName String Name of the exported function in provided path
      • options.handlerPath
      • options.handlerName

Examples

import express from 'express';
import awsSlsExpressMiddleware from 'aws-serverless-express/middleware';
import {customLocalLambdaAuthorizer} from 'lambda-custom-authorizer-middleware';

const app = express();

app.use(awsSlsExpressMiddleware.eventContext());
app.use(customLocalLambdaAuthorizer({ // Make sure to add after 'awsSlsExpressMiddleware'
 localAuthorizer: {
   handlerPath: '../other-project/lambda/auth',
   handlerName: 'handler'
 }
}));

app.get('/', (req, res) => res.json(req.apiGateway.event.requestContext.authorizer));
  • Throws Error Throws when config is not provided

Returns Function Express middleware function. Works only when IS_OFFLINE env var is set.

Development

Debug

This package uses debug library, so set environment variable like that to see the logs.

DEBUG=lambda-custom-authorizer-middleware:*

Lint

$ yarn lint

Build

$ yarn build

Docs

$ yarn docs

Tests

$ yarn test

Coverage

$ yarn coverage

Keywords

FAQs

Package last updated on 05 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc