Git Product home page Git Product logo

node-docker-lambda's Introduction

node-docker-lambda

Ever want to run your AWS Lambda functions somewhere other than AWS Lambda? Did you create some awesome Lambda only to find out it takes longer than 5 minutes to run? Not a problem! You can easily run your AWS Lambda function anywhere you can run Docker.

This is designed as a command line tool to help you wrap your existing (Node.js) AWS Lambda functions within a Docker container to run. You can also simply look at the Dockerfile and _container.js file here for examples in building your own Docker container.

It's useful if you want to sometimes run code in AWS Lambda while other times in a Docker container on your own servers or perhaps through ECS.

It assumes your AWS Lambda function exists within an index.js file as exports.handler() (for now). If you need to change this or change some of the options for the Docker container, you can use the copy command instead of the build command. This will give you the opportunity to change everything. If your needs are basic, you may be able to simply run the build command.

Installation

npm install -g node-docker-lambda

Usage

You'll want to run these commands from where your AWS Lambda code exists.

To just copy the boilerplate files over (Dockerfile and _container.js) to your current working directory, run:

ndl copy

This way you can alter the Dockerfile and even the little Lambda "emulator" as you see fit. Then manually build the Docker image.

If you want to build the Docker container right away, just run:

ndl build <name>

Where <name> is the repository name/tag of your container (it's the -t flag for Docker).

Running & Deploying

To run the container:

docker run container-name '{"event": "message"}'

You can deploy your Lambda Docker container to anywhere you'd normally deploy your Docker containers. Perhaps it's ECS. Especially if you are using other Amazon services. Note: Unlike AWS Lambda, you will not have an AWS session - so you will need to pass some credentials. Setting environment variables is a good way to do this. Edit the Dockerfile (you'll need to use the copy command and manually build the container) or use Amazon ECS to do it as an override in the Task.

Note: Amazon ECS lets you run Tasks directly from their web console. However, passing a JSON string to their form for the CMD override presented some challenges. When that data was passed along and eventually got handed to _container.js as an argument, it could not be parsed. At least for now, you can pass a base64 encoded JSON string which won't have any problems with escaping.

Don't forget, _container.js logs the results out to console (for context done(), fail() and succeed()) so use docker logs to see the output from your docker containers if you aren't running them from the command line yourself.

node-docker-lambda's People

Contributors

tmaiaroto avatar vladgolubev 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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

node-docker-lambda's Issues

Deploy to ECR/ECS

It would be nice to have another command that deploys the container to Amazon.

Catch all errors and exit

In case users don't handle all errors, add a handler to catch anything uncaught. Log then process.exit(). It is currently possible for containers to become "stuck" and not exit on uncaught exceptions.

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.