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

@mattnick/lambda-simple-event

v1.0.3

Published

LSE is a tool for easily parsing events sent to Lambda from API Gateway using the proxy integration setting. LSE also formulates syntactically correct responses.

Downloads

6

Readme

Lambda Simple Event (LSE)

LSE is a tool for easily parsing events sent to Lambda from API Gateway using the proxy integration setting. LSE also formulates syntactically correct responses.

Installation

Use the package manager npm to install LSE.

npm i @mattnick/lambda-simple-event

Usage

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
        return resolve(lse.success(200,{message: "OK"}));
    })
};

//Set Access-Control-Allow-Origin Header, defaults to "*"
const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
        lse.setAllowOriginHeaders('example.com');
        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Parsing post requests

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
  
        var body = lse.getAllPostBody();
        /* 
        {
            key1: "value1",
            key2: "value2"
        }
        */

        var key1 = lse.getPostBody('key1');
        // value1

        var key3 = lse.getPostBody('key3');
        // null

        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Parsing query string variables

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
  
        var queryString = lse.getAllQueryString();
        /* 
        {
            key1: "value1",
            key2: "value2"
        }
        */

        var key1 = lse.getQueryString('key1');
        // value1

        var key3 = lse.getQueryString('key3');
        // null

        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Parsing path parameters

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
  
        var params = lse.getAllPathParameters();
        /* 
        {
            key1: "value1",
            key2: "value2"
        }
        */

        var key1 = lse.getPathParameters('key1');
        // value1

        var key3 = lse.getPathParameters('key3');
        // null

        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Parsing Authorizer Context

Returns auth information from custom authorizers

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
  
        var auth = lse.getAuthorizerContext();
        /* 
        {
            userID: 9599,
            clientID: "3E2A9E6684218",
            ...
        }
        */

        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Other details

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
		
		//Retrieves API Keys Used by API Gateway 
        var apiKey = lse.getApiKey();
        // Returns: string or null
		
		//Returns the http path for the endpoint, does not include the stage
		var apiPath = lse.getApiPath();
		// /test/hello
		
		//Returns the current stage endpoint has been deployed using.
		var apiStage = lse.getApiStage();
		// /beta
		
		//Returns the http method used to call the endpoint
		var apiMethod = lse.getApiMethod();
		// post
		
		//Returns the ID of the API used
		var apiID = lse.getApiID();
		// a3fc4e

        return resolve(lse.success(200,{message: "OK"}));
    })
};

Example: Generating responses

const LambdaSimpleEvent = require('@mattnick/lambda-simple-event');

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
        var statusCode = 200,
        var body = {
	        message: "Hello World"
        };
        return resolve(lse.success(statusCode, body))
    })
};

exports.handler = async (event) => {
    return new Promise((resolve) => {
        const lse = new LambdaSimpleEvent(event);
        var statusCode = 500,
        var body = {
	        message: "Something went wrong"
        };
        return resolve(lse.error(statusCode, body))
    })
};

License

MIT