npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@madeelshabbir/serverless-offline-local-authorizers-plugin

v1.3.3

Published

[Serverless](http://www.serverless.com) plugin for adding authorizers when developing and testing functions locally with [serverless-offline](https://github.com/dherault/serverless-offline).

Downloads

5

Readme

serverless-offline-local-authorizers-plugin

Serverless plugin for adding authorizers when developing and testing functions locally with serverless-offline.

Serverless npm npm

This plugin allows you to add local authorizer functions to your serverless projects. These authorizers are added dynamically in a way they can be called by serverless-offline but don't interfer with your deployment and your shared authorizer functions. This helps when you have shared API Gateway authorizers and developing and testing locally with serverless-offline.

:warning: If you are using this plugin and get schema validation errors: Please check indentation of localAuthorizer: config property! See example below...

Installation

Installing using npm:

npm i serverless-offline-local-authorizers-plugin --save-dev

Usage

Step 1: Define your authorizer functions in a file of your choice (.js, .mjs, .ts and others) and later you will inform the path and name or file default called local-authorizers.js and put it into your project root (that's where your serverless.yml lives).

If you want the local function to call your deployed shared authorizer it could look something like this:

const AWS = require("aws-sdk");
const mylocalAuthProxyFn = async (event, context) => {

  const lambda = new AWS.Lambda();
  const result = await lambda.invoke({
    FunctionName: "my-shared-lambda-authorizer",
    InvocationType: "RequestResponse",
    Payload: JSON.stringify(event),
  }).promise();

  if (result.StatusCode === 200) {
    return JSON.parse(result.Payload);
  }

  throw Error("Authorizer error");
};

module.exports = { mylocalAuthProxyFn };

Of course you could also just return a mocked response, call Cognito to mock your Cognito Authorizer or whatever suits your needs. You can also define multiple authorizer functions if you need to.

Step 2: In your serverless.yml, add the localAuthorizer property to your http events. This will not interfere with your "real" authorizers and will be ignored upon deployment.

functions:
  myFunction:
    handler: myFunction.handler
    events:
      - http:
          path: /my/api/path
          method: GET
          authorizer:
            type: CUSTOM
            authorizerId: abcjfk
          localAuthorizer:
            name: "mylocalAuthProxyFn"
            pathFile: "local-authorizers.js" # Optional
            type: "request"

Step 3: Add the plugin path to the plugins sections in serverless.yml:

plugins:
  - ./node_modules/@madeelshabbir/serverless-offline-local-authorizers-plugin
  - serverless-offline

Step 4: Fire up serverless offline with the local-authorizers option:

$ sls offline local-authorizers --stage dev --region eu-central-1

License

MIT