All Projects → ashiina → Lambda Local

ashiina / Lambda Local

Licence: mit
Commandline tool to run Amazon Lambda function on local machines.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Lambda Local

Es2017 Lambda Boilerplate
AWS Lambda boilerplate for Node.js 6.10, adding ES2018/7/6 features, Docker-based unit testing and various CI/CD configurations
Stars: ✭ 169 (-71.69%)
Mutual labels:  lambda, aws-sdk
Awesome Aws
A curated list of awesome Amazon Web Services (AWS) libraries, open source repos, guides, blogs, and other resources. Featuring the Fiery Meter of AWSome.
Stars: ✭ 9,895 (+1557.45%)
Mutual labels:  lambda, aws-sdk
Aws Sdk Js V3
Modularized AWS SDK for JavaScript.
Stars: ✭ 737 (+23.45%)
Mutual labels:  lambda, aws-sdk
aws-lambda-powertools-typescript
A suite of utilities for AWS Lambda Functions that makes structured logging, creating custom metrics asynchronously and tracing with AWS X-Ray easier
Stars: ✭ 817 (+36.85%)
Mutual labels:  lambda, aws-sdk
Dazn Lambda Powertools
Powertools (logger, HTTP client, AWS clients, middlewares, patterns) for Lambda functions.
Stars: ✭ 501 (-16.08%)
Mutual labels:  lambda
Udacity Data Engineering Projects
Few projects related to Data Engineering including Data Modeling, Infrastructure setup on cloud, Data Warehousing and Data Lake development.
Stars: ✭ 458 (-23.28%)
Mutual labels:  aws-sdk
Lambdaphp
Quick and Dirty PHP website hosting using Aws Lambda
Stars: ✭ 449 (-24.79%)
Mutual labels:  lambda
Vercel Php
▲ Vercel PHP runtime • vercel-php • now-php • 🐘+ λ = ❤
Stars: ✭ 429 (-28.14%)
Mutual labels:  lambda
Puppeteer Lambda Starter Kit
Starter Kit for running Headless-Chrome by Puppeteer on AWS Lambda.
Stars: ✭ 563 (-5.7%)
Mutual labels:  lambda
Klayers
Python Packages as AWS Lambda Layers
Stars: ✭ 557 (-6.7%)
Mutual labels:  lambda
Webiny Js
Enterprise open-source serverless CMS. Includes a headless CMS, page builder, form builder and file manager. Easy to customize and expand. Deploys to AWS.
Stars: ✭ 4,869 (+715.58%)
Mutual labels:  lambda
Functions
Tutorials, examples, workshops and a playground for serverless with Netlify Functions
Stars: ✭ 463 (-22.45%)
Mutual labels:  lambda
Cloudformation templates
AWS - CloudFormation Templates
Stars: ✭ 505 (-15.41%)
Mutual labels:  lambda
Honeylambda
honeyλ - a simple, serverless application designed to create and monitor fake HTTP endpoints (i.e. URL honeytokens) automatically, on top of AWS Lambda and Amazon API Gateway
Stars: ✭ 454 (-23.95%)
Mutual labels:  lambda
Minimal
A Delightfully Diminutive Lisp. Implemented in < 1 KB of JavaScript with JSON source, macros, tail-calls, JS interop, error-handling, and more.
Stars: ✭ 560 (-6.2%)
Mutual labels:  lambda
Serverlessui
A command-line utility for deploying serverless applications to AWS. Complete with custom domains, deploy previews, TypeScript support, and more.
Stars: ✭ 434 (-27.3%)
Mutual labels:  lambda
Mangum
AWS Lambda & API Gateway support for ASGI
Stars: ✭ 475 (-20.44%)
Mutual labels:  lambda
Fn
The container native, cloud agnostic serverless platform.
Stars: ✭ 5,046 (+745.23%)
Mutual labels:  lambda
Cloudfront Auth
An AWS CloudFront [email protected] function to authenticate requests using Google Apps, Microsoft, Auth0, OKTA, and GitHub login
Stars: ✭ 471 (-21.11%)
Mutual labels:  lambda
Aws Serverless Ecommerce Platform
Serverless Ecommerce Platform is a sample implementation of a serverless backend for an e-commerce website. This sample is not meant to be used as an e-commerce platform as-is, but as an inspiration on how to build event-driven serverless microservices on AWS.
Stars: ✭ 469 (-21.44%)
Mutual labels:  lambda

Lambda-local

NPM

Build Status

Lambda-local lets you test NodeJS Amazon Lambda functions on your local machine, by providing a simplistic API and command-line tool.

It does not aim to be perfectly feature proof as projects like serverless-offline or docker-lambda, but rather to remain very light (it still provides a fully built Context, handles all of its parameters and functions, and everything is customizable easily).

The main target are unit tests and running lambda functions locally.

Install

npm install -g lambda-local

Build

make build

Or

npm install
npm install --only=dev
npm run build

Usage

  • As an API: You can also use Lambda local directly in a script. For instance, it is interesting in a MochaJS test suite in order to get test coverage.
  • As a command line tool: You can use Lambda-local as a command line tool.

If you're unsure about some definitions, see Definitions for terminology.

About: API

LambdaLocal

API accessible with:

const lambdaLocal = require("lambda-local");

Or on TypeScript (supported on 1.7.0+):

import lambdaLocal = require("lambda-local");

lambdaLocal.execute(options)

Executes a lambda given the options object, which is a dictionary where the keys may be:

Key name Description
event requested event as a json object
lambdaPath requested path to the lambda function
lambdaFunc pass the lambda function. You cannot use it at the same time as lambdaPath
profilePath optional, path to your AWS credentials file
profileName optional, aws profile name. Must be used with
lambdaHandler optional handler name, default to handler
region optional, AWS region, default to us-east-1
timeoutMs optional, timeout, default to 3000 ms
environment optional, extra environment variables for the lambda
envfile optional, load an environment file before booting
envdestroy optional, destroy added environment on closing, default to false
verboseLevel optional, default 3. Level 2 dismiss handler() text, level 1 dismiss lambda-local text and level 0 dismiss also the result.
callback optional, lambda third parameter callback. When left out a Promise is returned
clientContext optional, used to populated clientContext property of lambda second parameter (context)

lambdaLocal.setLogger(logger)

lambdaLocal.getLogger()

Those functions allow to access the winston logger used by lambda-local.

API examples

A lot of examples, especially used among Mocha, may be found in the test files over: here

Basic usage: Using Promises
const lambdaLocal = require('lambda-local');

var jsonPayload = {
    'key': 1,
    'another_key': "Some text"
}

lambdaLocal.execute({
    event: jsonPayload,
    lambdaPath: path.join(__dirname, 'path_to_index.js'),
    profilePath: '~/.aws/credentials',
    profileName: 'default',
    timeoutMs: 3000
}).then(function(done) {
    console.log(done);
}).catch(function(err) {
    console.log(err);
});

Basic usage: using callbacks

const lambdaLocal = require('lambda-local');

var jsonPayload = {
    'key': 1,
    'another_key': "Some text"
}

lambdaLocal.execute({
    event: jsonPayload,
    lambdaPath: path.join(__dirname, 'path_to_index.js'),
    profilePath: '~/.aws/credentials',
    profileName: 'default',
    timeoutMs: 3000,
    callback: function(err, data) {
        if (err) {
            console.log(err);
        } else {
            console.log(data);
        }
    },
    clientContext: JSON.stringify({clientId: 'xxxx'})
});

About: CLI

Available Arguments

  • -l, --lambda-path <lambda index path> (required) Specify Lambda function file name.
  • -e, --event-path <event path> (required --watch is not in use) Specify event data file name.
  • -h, --handler <handler name> (optional) Lambda function handler name. Default is "handler".
  • -t, --timeout <timeout> (optional) Seconds until lambda function timeout. Default is 3 seconds.
  • -r, --region <aws region> (optional) Sets the AWS region, defaults to us-east-1.
  • -P, --profile-path <aws profile name> (optional) Read the specified AWS credentials file.
  • -p, --profile <aws profile name> (optional) Use with -P: Read the AWS profile of the file.
  • -E, --environment <JSON {key:value}> (optional) Set extra environment variables for the lambda
  • --wait-empty-event-loop (optional) Sets callbackWaitsForEmptyEventLoop=True => will wait for an empty loop before returning. This is false by default because our implementation isn't perfect and only "emulates" it.
  • --envdestroy (optional) Destroy added environment on closing. Defaults to false
  • -v, --verboselevel <3/2/1/0> (optional) Default 3. Level 2 dismiss handler() text, level 1 dismiss lambda-local text and level 0 dismiss also the result.
  • --envfile <path/to/env/file> (optional) Set extra environment variables from an env file
  • --inspect [[host:]port] (optional) Starts lambda-local using the NodeJS inspector (available in nodejs > 8.0.0)
  • -W, --watch [port] (optional) Starts lambda-local in watch mode listening to the specified port [1-65535].

CLI examples

# Simple usage
lambda-local -l index.js -h handler -e examples/s3-put.js

# Input environment variables
lambda-local -l index.js -h handler -e examples/s3-put.js -E '{"key":"value","key2":"value2"}'

Running lambda functions as a HTTP Server

A simple way you can run lambda functions locally, without the need to create any special template files (like Serverless plugin and SAM requires), just adding the parameter --watch. It will raise a http server listening to the specified port (default is 8008), then you can pass the event payload to the handler via request body.

lambda-local -l examples/handler_helloworld.js -h handler --watch 8008

curl --request POST \
  --url http://localhost:8008/ \
  --header 'content-type: application/json' \
  --data '{
	"event": {
		"key1": "value1",
		"key2": "value2",
		"key3": "value3"
	}
}'

About: Definitions

Event data

Event sample data are placed in examples folder - feel free to use the files in here, or create your own event data. Event data are just JSON objects exported:

// Sample event data
module.exports = {
	foo: "bar"
};

Context

The context object has been sampled from what's visible when running an actual Lambda function on AWS, and the available documentation They may change the internals of this object, and Lambda-local does not guarantee that this will always be up-to-date with the actual context object.

AWS-SDK

Since the Amazon Lambda can load the AWS-SDK npm without installation, Lambda-local has also packaged AWS-SDK in its dependencies. If you want to use this, please use the -p or -P options (or their API counterpart) with the aws credentials file. More infos here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files

Other links

Development

  • Run make to install npm modules. (Required to develop & test lambda-local)
  • Run make test to execute the mocha test.
  • Run make clean to reset the repository.

License

This library is released under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].