Git Product home page Git Product logo

docker-lambda-api-server's Introduction

docker-lambda-api-server

A companion tool for the awesome docker-lambda sandbox.

This is a very basic, local AWS Lambda API server that lets you invoke your lambda functions via the AWS SDK instead of running Docker from the command-line or docker-lambda Node helper.

It also leverages (although very limited at this point) the new AWS Cloudformation SAM template.

Prerequisites

Same as docker-lambda.

Tested with the latest Node LTS (v6.9.1).

Installation

npm install docker-lambda-api-server

Example

Let's suppose you have 2 functions: hello and goodbye.

// hello.js
exports.handler = function(event, context, cb) {
  cb(null, JSON.stringify({hello: 'world'}))
}
// goodbye.js
exports.handler = function(event, context, cb) {
  cb(null, JSON.stringify({good: 'bye'}))
}

First thing you need to do (if you haven't already), is to create a SAM template like this:

# /greetings.yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  SayHello:
    Type: AWS::Serverless::Function
    Properties:
      Handler: hello.handler
      Runtime: nodejs4.3
 
  SayGoodbye:
    Type: AWS::Serverless::Function
    Properties:
      Handler: goodbye.handler
      Runtime: nodejs4.3

As you can see above, we created the definition for our 2 functions, which we named SayHello and SayGoodbye, each one pointing to the right code file.

We are now ready to start the API server:

docker-lambda-api-server -f greetings.yml

An HTTP server will start listening at localhost:3000. You can do a quick test by invoking any of your functions via the AWS Lambda REST API:

curl http://localhost:3000/2015-03-31/functions/SayHello/invocations

{"hello":"world"}

Or you can also invoke the function via the AWS SDK:

import { Lambda } from 'aws-sdk'

let lambda = new Lambda({
  region: 'foo-west-1',
  endpoint: 'http://localhost:3000'
})

lambda
  .invoke({ FunctionName: 'SayGoodbye' })
  .promise()
  .then(result => console.log(result))

Documentation

// TODO

In the meanwhile, you can run

docker-lambda-api-server -h

to see all the options available.

You can also check out the provided example.

TODO

  • Unit tests?
  • Proper runtime validation (node, node4.3)
  • Implement ClientContext
  • Implement InvocationType
  • Implement Qualifier
  • Implement LogType
  • Implement environment variables in SAM template
  • Your suggestion here

docker-lambda-api-server's People

Contributors

luisfarzati avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mpetrunic

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.