Coder Social home page Coder Social logo

thewillhuang / lambdaws Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mentum/lambdaws

0.0 0.0 0.0 248 KB

Deploy, run and get results from Amazon AWS Lambda in a breeze

Home Page: http://mentum.github.io/lambdaws

License: GNU Lesser General Public License v3.0

JavaScript 100.00%

lambdaws's Introduction

logo Lambdaws

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

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.

AWS Lambda

AWS Lambda Preview is now open to all customers. This means everybody can give Lambdaws a try!

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

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 without dependencies

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

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(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
);

Overriding default settings

λ(yourFunc, {
	memory: 256, // mb
	description: 'Description of your function',
	timeout: 10 // seconds
});

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: ''  // string, AWS ARN. Must have full access to SQS.
    });
    
    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: ''  // string, AWS ARN. Must have full access to SQS.
    });
    
    lambdaws.start();

Your AWS user credentials must have access to Lambda, SQS and S3.

Full working example

See example/example.js

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.

lambdaws's People

Contributors

chriskuehl avatar eff avatar gitter-badger avatar osylvain avatar willyg302 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.