Code Monkey home page Code Monkey logo

lambda's Introduction

@medial/lambda

Build Status codecov Known Vulnerabilities Total alerts Language grade: JavaScript

A wrapper for AWS Lambda

A wrapper to help build AWS Lambda backed HTTP services.

Features

  • Validation via Joi
    • Headers
    • Path Params
    • Query Params
    • Payload
  • Error responses via Boom
  • handles complexities of dealing with lambda functions (For example: multiple values for the same key in queryParams)

Please checkout the full example

Inspired by the hapi framework.

Example

Medial Handler Object

const Lambda = require('@medial/lambda');
const Boom = require('@hapi/boom');
const Joi = require('@hapi/joi');


exports.get = Lambda.define({
  validate: {
    query: Joi.object().keys({
      world: Joi.string().default('world')
    })
  },
  handler: async function(request, h) {
    const world = request.query.world;

    return {hello: world};
  }
});

exports.get is now a AWS Lambda function. Once this function is configured for HTTP access via the AWS API Gateway - when invoked, it will return {"hello": "world"} with a response code of 200.

You can also invoke the lambda from another lambda. The response will look like this:

{
  multiValueHeaders: {},
  statusCode: 200,
  body: '{"hello": "world"}' // this is stringifyed object 
}

Working example

Deploy the example to AWS and/or run it locally with swagger documentation

A full example

Documentation

lambda's People

Contributors

amitkirdatt avatar dependabot[bot] avatar snyk-bot 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.