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

njax-aws-lambda

v0.0.2

Published

Allows you to test and build lambda's locally then deploy to AWS

Downloads

5

Readme

njax-aws-lambda

This is a tool kit that allows

##API: ###Install:

npm install -S njax-aws-lambda

###Setting up your app:

var NJaxLambda = require('njax-aws-lambda');
var app = NJaxLambda();

###Set Up A Lambda: This will create a LambdaRouter. This acts similar to an express router for the lambda.

var eventsLambda = app.lambda('myFirstLambda');

###Set Up A APIGateway route: ####Single Default Method:

lambda.get('/some/uri', './rel/path/to/lambda');

The contents on ./rel/path/to/lambda can be found below in the Lambda Module Setup section.

####Single Custom Method:

lambda.get('/some/uri', './rel/path/to/lambda#method');

####Multiple Custom Methods:

lambda.get('/some/uri', [
    './rel/path/to/lambda#methodA',
    './rel/path/to/lambda#methodB',
    './rel/path/to/lambda#methodC'
]);

###Kinesis Usage: ####Basic Usage: The following will funnel all events to a single lambda

lambda.kinesis(
    'arn:aws:kinesis:EXAMPLE',
    [
        './rel/path/to/lambda#run'
    ]
);

####Advanced Usage: The following will filter out by event. WARNING: THIS IS REALLY EXPERIMENTAL AND UNDOCUMENTED

lambda.kinesis(
    'arn:aws:kinesis:EXAMPLE#some:event:name',
    [
        './rel/path/to/lambda#run'
    ]
);

###Lambda Module Setup: Inside of the actually Lambda Module (In these examples has lived at ./rel/path/to/lambda you will need to put the code that actually fires off.

####Basic Setup: The code is the same basically as typical lambda code.

module.exports = {
    run: function (event, context, next) {
        //Do stuff

    }
}

####APIGateway Lambda Event Structure: When setting a Lambda to be triggered by APIGateway the event has been modeled to roughly resemble the req param you see in middleware.

module.exports = {
    run: (event, context, next) => {
        //Do stuff
        console.log(event);//CONTENTS BELOW
    }
}
/*
{
    method: 'get',
    headers: {
        'Content-Type':'application/json'
    },
    query: {
        query_stirng_var:true
    },
    body: {
        post_body_vars:'true'
    },
    params: {
        stuff:'123',
        pulled:'456',
        out:'789'
        'of_the_uri_path':'bananas
    },
    route:{
        path: /* the route in api gateway
    }
}
*/

NOTE: We are trying to add as many of these as possible to make it as close to express as possible. Feel free to fork this project and add some if you like.

####Requireing Files: Since AWS Lambda don't install their own dependencies and you will need to define which dependencies you want packaged with the module: NOTE: These are relative to the root of the project

module.exports = {
    _requires: {
        '/node_modules/underscore*': true,
        '/node_modules/request*': true,
        '/lib/lambdas/some/sub/dir/*': true,
    },
    run: (event, context, next) => {
        //Do stuff

    }
}

####On Boot: Some times you want to run things only once when the Lambda is booted up in memory. Things like connecting to a service like Redis. For this you can use the Lambda Module's _onBoot property.

const Redis = require('redis');
module.exports = {
    _onBoot: (config) =>{
        this.redis = Redis.createClient(config);
    },
    _requires: {
        '/node_modules/redis*': true,
        /* ... */
    },
    run: (event, context, next) => {
        //Do stuff

    }
}

NOTE: A config parameter is passed in. See the Configuration Files and Environments section for details on that.

###Lambda Configuration Files and Environments: When you start a project for local dev or when you deploy a project you can set the Environment. Using the command line tool below that is set with the -e argument.

This will require the .js file at the following path:

{project root}/config/{environment}.js

This way you can have different configurations based on the environment.

##Command Line Tool Usage: ###Installing:

npm install njax-aws-lambda -g

###Initializing a Project: Go to the root of your project and run.

nlambda init

This will create a folder called _lambda at the root of your project. This folder contains the following:

  • Configurations specific to your project
  • The build directory of your Lambdas for when they get packaged into Zip to be uploaded to AWS.

####./_lambda/config.json: NOTE: The plan is to move as much of this manual config into the nlambda init setup. Were not there quite yet but hang with us

{
   "region": "us-east-1",
   "apigateway": "...",
    "role": "arn:aws:iam::...",//The
}
  • region - The AWS Region your lambdas will live in
  • apigateway - The APIGateway ID that will proxy HTTP/HTTPS requests to your lambda
  • role - An IAM Role that your lambda will be acting on behalf of.

It will also create a lambdas property automatically. That keeps some basic info on each of the Lambda's you created earlier.

###Running Locally: Navigate to the root of the application and run the following:

nlambda start

It should start a local express server that mimics the URL structure you have for the APIGateway

###Deploying the Lambda Module: The following will package the code for the lambdas into a zip and push the code for the lambdas to the servers

nlambda deploy -e production -l myFirstLambda

_NOTE: This does NOT setup the Triggers for the Lambdas. This only pushes the code. Use the following to push setup the Triggers. ###Deploying the Lambdas' triggers: This sets up the following:

  • Any associations between the APIGateway and your Lambdas
  • Any association between kinesis and your Lambdas
nlambda deploy-gateway -e production -l myFirstLambda

##TODO:

  • nlambda export-swagger

###Notes: