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

lambdaws

v1.0.15

Published

AWS lambda functions made easy

Downloads

48

Readme

logo Lambdaws

![Gitter](https://badges.gitter.im/Join Chat.svg) Build Status

Using Amazon's Lambda Service, Lambdaws cloudifies any JavaScript function — including existing libraries — with no extra code. It removes the friction you get when using AWS Lambda directly. The goal of Lambdaws is to make it trivial to build highly scalable, highly available applications.

Features

Lambdaws will automatically:

  • Create a new SQS Queue for your function
  • Instrument your function/module to store the result on that SQS Queue
  • Zip your function/module
  • Include any dependencies needed from your module in the zip file
  • Upload the zip file to AWS Lambda
  • Instantly provide your application with the execution result as soon as it is available (by using SQS long-polling)
  • Detect any change to your library and re-upload it if needed
  • Install large required system libraries like phantomjs
  • Detect execution timeouts and throw an appropriate error when it occurs

Lambdaws will not:

  • Alter your function or module
  • Re-upload the function on every call
  • Add much overhead

Installation

npm install lambdaws

Usage

Inline functions

λ takes an inline asynchronous function and deploy it to AWS Lambda. If you call cloudedCalculator it will run in the cloud.

This is not the recommended way of working with Lambdaws and should only be used for testing purposes. Modules should be used whenever possible.

Please note that λ is used here only for shortening the code and for clarity.

var λ = require('lambdaws').create;

// A simple inlined asynchronous function computing A + B
var calculator = function(a, b, callback) { 
	callback(a + b);
};

// This will automatically instrument and upload your function to AWS Lambda
var cloudedCalculator = λ(calculator);

// cloudedCalculator is a reference to the function in the cloud.
// Therefore calling this function will invoke it on AWS Lambda rather than locally.
cloudedCalculator(5, 2, function(err, data) {
	// Automatic instrumentation of the code added a SQS message push of the result
	// the result of the function is then available in real time without polling CloudWatch
	console.log(data); // Prints 7
});

Functions inside modules with external dependencies

var cloudedCalculator = λ(
	'./my_module', // Relative path to module
	'functionNameInsideModule', // The name of the function in the module. Optional if module returns a function.
	['async', 'request'], // External dependencies. Must reside in node_modules for now.
	{ description : 'my custom description' } // Settings override
);

Using large external libraries

You can tell Lambdaws to download and install system libraries. An example of library is phantomjs. The available libraries can be found on this repository. Feel free to make pull requests to add new libraries. The reason for this feature is that lambda has max upload size of 30Mb.

var cloudedBrowser = λ(
	'./my_module_depending_on_phantomjs', // Relative path to module
	'functionNameInsideModule', // The name of the function in the module. Optional if module returns a function.
	['Q', ':phantomjs'], // External libraries are prepended with ":"
	{ name : 'PhantomJSExample' } // Settings override
);

Overriding default settings

λ(yourFunc, {
	name: '', // (string) defaults to 'default'
	memory: '256', // (string) defaults to '128'
	description: 'Description of your function', // (string) defaults to ''
	timeout: 10, // (int, seconds) defaults to 3 seconds,
	ignoreResponse: true // Will not send results back to SQS, function will run ~ 150ms faster
});

Setting your AWS credentials

You can set your AWS credentials in one of three ways.

  1. By default, the AWS SDK looks for credentials in ~/.aws/credentials. If you do not set anything, lambdaws will use the default profile. For more information see the docs.

  2. You can use a different profile:

    var lambdaws = require('lambdaws');
    
    lambdaws.config({
        credentials: 'my-profile',  // string, profile name.
        role: '' // ** Required **
    });
    
    lambdaws.start();
  3. You can set the access and secret keys manually:

    var lambdaws = require('lambdaws');
    
    lambdaws.config({
        credentials: {
            accessKey: '',  // string, AWS AccessKeyId.
            secretKey: '',  // string, AWS AccessKeySecret.
        },
        role: '' // ** Required **
    });
    
    lambdaws.start();

The role is a ARN of the IAM role that AWS Lambda can assume to push to SQS, S3 and any other AWS services you are using inside your Lambda function. You need to give the role those policies.

Full working example

See example/example.js

Upload functions using the Command Line Interface (CLI)

Documentation needed. See bin/lambdaws-cli.js for implementation and usage.

Limitations

The same constraints imposed by AWS Lambda apply. Your function should also be stateless and independent of the underlying architecture. Be also aware that any variable that your function uses must be declared by your function. Global and outer-scope variables are not uploaded to AWS Lambda.

Roadmap

Public Trello Board

Contributions

This repo is in early stage so don't be shy and report bugs if you find some. Contributions are more than welcomed! Please visit the Trello Board to vote and see which cards are the most in-demand. When you decide to tackle a card, please move it to the according list, assign it to yourself, and make a pull request.