What's this

Introduction

Current released version: v0.1.0beta.0

Why Lambda? Currently developers are looking to expose capabilities via APIs, but often spend lots of time deploying a solution. Developers are deploying API management solutions which are too complex & do not provide the features they intended. These APIs often utilize open source frameworks which require hosting & maintenance by the end user. This is where Nano Lambda saves the day. You can now expose code via APIs and push micro-services to production, while abstracting all the pain elements such as, scaling, performance, security, logging, compliance, etc.. So why lambda? Deploying that micro-service which took you 15 min to write will take you 30 seconds.

What is Nano Lambda?

Nano Lambda is an automated compute service which runs and scales your micro-services. First, you will upload your code into a highly optimized and secure Nano Container. Next, Nano's Flock service will orchestrate, outside the container, the required tasks to network,run, scale, secure, authenticate and log your micro-service. We do not add, see or change any code inside the container. Unlike other lambda services.

Known Issues, Product State

Current state of the product is beta, which means that the use cases are tested only for the positive use cases. There is an effort underneath to test all possible negative & edge cases, but that is not the goal or objective of this particular release v0.1.0beta.0


  • The current release is meant for Single Node testing installations. Whilst a production install comprises of multi-node installation, this release does not work for multi-node. Our General Availability "GA" release will target multi-node enterprise installations.

  • User management, Authentication is missing:
    Yes, to make it easy for users to test the beta release, User management & authentication is stripped out of the product, just like the multi-node setup.

  • I cannot configure event sources, to invoke Lambda:
    Yes, while AWS Lambda does offer the flexibility to configure event sources, our Product is not aimed at configuring event sources. Instead, you can plugin available open source adapters in your Lambda code to make that happen. Email us if you need help. Examples will come soon.

  • Wait, how does Lambda handle event sources, when it is not long living?
    In fact, our version of Lambda is long living.

  • What features are supported in this release?
    Nice question; You can deploy a Lambda, and invoke it via HTTP. Also, you can see the Metrics via our visualization tool & Logs via our search tool.

  • What is the Roadmap?
    With the GA, we are bringing unified API endpoints for deploying a Lambda, invoking it via HTTP, Metrics & Logs, which are currently exposed via different endpoints. There are 18 months of planned releases, along with more language support.

Unboxing

Beyond the Examples

How to develop your own lambda micro-service.

First, sign up for an account (beta list for now) and receive the test server or the on-premise installation files.

Nano Lambda will run native nodejs and expressjs applications.
In order for your native app to run, follow the few requirements below.


Requirements

  • ONLY upload a .zip or .tar compressed file.
  • This compressed file must contain ONLYserver.js and package.json.
  • If other files are present in the compressed file your lambda will do nothing. This is on purpose.

Requirement 1: package.json should contain dependencies [per node.js ]

Why?: Nano Lambda runs a npm install production before starting your Lambda.


Requirement 2: package.json should include main [ main module ]

Why?: Because Nano uses npm start to instantiate your Lambda, which internally looks for the main script to pass on to node executable.

Example package.json

{
  "name": "micro-api",
  "version": "0.0.1",
  "description": "micro-api",
   "main": "server.js", //*Requirement*
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
             },
  "author": "Nano Lambda",
  "license": "MIT",
  "dependencies": {
    "morgan": "^1.7.0",
    "express": "^4.13.3",
    "response-time": "^2.3.1"
                    }
}                    

Requirement 3:server.js should always listen on PORT=3000

Why?: This is the only port exposed for listening.

  • server.js is a reference to the main module described above
  • Example server.js

    
     /**
     * start the http server
     */
    
    http_server.listen(3000);
    
    
                        

    Requirement 4:server.js should expose a Health Endpoint on /healthz

    Why?: Nano runs Health checks on your Lambda, to ensure it is operational.

  • server.js is a reference to the main module described above
  • Add the below code to server.js

    
    /**
     * health endpoint
     */
    
    http_server.get('/healthz', function(req, res) {
        'use strict';
        
        res.status(200).send('OK');
    });
    
                        
    Better understanding

    Starter template

    You need to start somewhere. Use this template  or   take a look at our examples section

    Here is template for package.json andserver.js respectively. You can copy this code and add functionality from here.

    
    /*package.json*/
    {
      "name": "micro-api",
      "version": "0.0.1",
      "description": "micro-api",
      "main": "server.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "author": "Nano Lambda",
      "license": "MIT",
      "dependencies": {
        "morgan": "^1.7.0",
        "express": "^4.13.3",
        "response-time": "^2.3.1"
      }
    }
    
    
    
    
    /* jshint strict: true */
    /* jshint esversion: 6 */
    /* global require, Buffer */
    
    
    /**
     * module dependencies
     */
    
    var morgan  = require('morgan');
    var express = require('express');
    
    
    /**
     * instantiate express
     */
    
    var http_server = express();
    
    
    /**
     * disable x-powered-by header
     * enable etag, strict mode
     */
    
    http_server.disable('x-powered-by');
    http_server.enable('etag', 'strict');
    
    
    /**
     * `set_pod_headers`
     *
     *      - sets Pod headers
     */
    
    function set_pod_headers(req, res, next) {
        'use strict';
        
        res.setHeader('X-Pod-Name', process.env.POD_NAME || '');
        res.setHeader('X-Pod-IP', process.env.POD_IP || '');
        next();
    }
    
    
    /**
     * middleware lets you define common
     * functionality across resources,
     * so you don't have to re-define
     */
    
    http_server.use(morgan('combined'));
    http_server.use('*', set_pod_headers);
    http_server.use((require('response-time'))());
    
    
    /**
     * mount the API
     */
    
    http_server.get('*', function(req, res) {
        'use strict';
    
        res.status(200).send({
            date: (new Date).getTime()
        });
    });
    
    
    /**
     * health endpoint
     */
    
    http_server.get('/healthz', function(req, res) {
        'use strict';
        
        res.status(200).send('OK');
    });
    
    
    /**
     * start the http server
     */
    
    http_server.listen(3000);
    
    
    Lambda Review

    Quick start steps

    Time to start writing your micro-service. It won't take more than 10 minutes to start.

    • Prepare your zip file

      Compress server.js and package.json.

      ~$ zip -r micro_service.zip micro-service/

    • Upload your micro-service

      cd to zip directory. Flag -v is optional.

      ~$ curl -v -X POST https://{{your_lambda_url}}/v1/lambda
                              -F "lambda_name=your_service" /
                              -F "lambda_version=v1" /
                              -F "lambda_memory_limit=50Mi" /
                              -F "[email protected]_service.zip"
                              

    • Get Authorization Token

      Get your Auth token:
      Query version:

      ~$ curl -X POST https://{{your_lambda_url}}/v1/token?api_key={{API_KEY}}&api_secret={{API_SECRET}}
      Body version:
      ~$ curl -X POST https://{{your_lambda_url}}/v1/token /
              -d "api_key={{API_KEY}}&api_secret={{API_SECRET}}"

    • Call your micro-service

      Call your service endpoint:

      ~$ curl https://{{your_lambda_url}}/v1/services/micro-api
                    -u {{your_AuthToken}}:[AuthToken]

    Sign Up or Check out these Examples!