New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lambda-lambda-lambda

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-lambda-lambda

AWS Lambda@Edge serverless application router.

Source
npmnpm
Version
0.0.5
Version published
Weekly downloads
1
-50%
Maintainers
1
Weekly downloads
 
Created
Source

lambda-lambda-lambda

npm version Build Status

AWS Lambda@Edge serverless application router.

lambda-lambda-lambda

Features

  • ECMAScript 2015 (ES6) compatible.
  • Routes and URI resource support.
  • Local/Globally scoped middleware.
  • Lightweight/cost effective solution.

Dependencies

Installation

Install package dependencies using NPM.

$ npm install lambda-lambda-lambda

Usage

Lambda function

// .. sam-app/src/app.js

'use strict';

// Load module.
const Router = require('lambda-lambda-lambda');

/**
 * @see AWS::Serverless::Function
 */
exports.handler = (event, context, callback) => {
  const {request, response} = event.Records[0].cf;

  const router = new Router(request, response);
  router.setPrefix('/api');

  // Middleware (order is important).
  router.use(function(req, res, next) {
    if (req.method() === 'CONNECT') {
      res.status(405).send();
    } else {
      next();
    }
  });

  // Send root response.
  router.get('/', function(req, res) {
    res.status(501).send();
  });

  // .. everything else.
  router.default(function(req, res) {
    res.status(404).send();
  });

  callback(null, router.response());
};

Route handler

// .. sam-app/src/routes/foo.js

'use strict';

/**
 * @export {Object}
 */
module.exports = {
  middleware: [],
  resource: false,

  /**
   * GET /api/foo
   */
  index (req, res) {
    res.setHeader('Content-Type', 'text/html');
    res.status(200).send('Lambda, Lambda, Lambda');
  },

  /**
   * PUT /api/foo
   */
  create (req, res) {
    res.status(201).send();
  },

  /**
   * PATCH /api/foo
   */
  update (req, res) {
    res.status(204).send();
  },

  /**
   * DELETE /api/foo
   */
  delete (req, res) {
    res.status(410).send();
  },

  /**
   * POST /api/foo
   */
  submit (req, res) {
    res.status(200).send();
  }
};

Resource handler

// .. sam-app/src/routes/foo/bar.js

'use strict';

/**
 * @export {Object}
 */
module.exports = {
  middleware: [],
  resource: true,

  /**
   * GET /api/foo/bar/<resourceId>
   */
  index (req, res, id) {
    res.setHeader('Content-Type', 'application/json');
    res.status(200).json({and: 'Omega Mu'});
  },

  /**
   * PUT /api/foo/bar/<resourceId>
   */
  create (req, res, id) {
    res.status(201).send();
  },

  /**
   * PATCH /api/foo/bar/<resourceId>
   */
  update (req, res, id) {
    res.status(204).send();
  },

  /**
   * DELETE /api/foo/bar/<resourceId>
   */
  delete (req, res, id) {
    res.status(410).send();
  },

  /**
   * POST /api/foo/bar/<resourceId>
   */
  submit (req, res, id) {
    res.status(200).send();
  }
};

Middleware

// .. sam-app/src/middleware/ContentTypeHeader.js

'use strict';

/**
 * Middleware to send Content-Type header.
 */
module.exports = (req, res, next) => {
  res.setHeader('Content-Type', 'text/html');

  next();
};

App Example

A deployable application has been provided with this package. In order to successfully deploy you must have set-up your AWS Config and have created an IAM user with the following policies:

Developers

CLI options

Run ESLint on project sources:

$ npm run lint

Generate documentation using ESDoc:

$ npm run gendoc

Run Mocha integration tests:

$ npm run test

Contributions

If you fix a bug, or have a code you want to contribute, please send a pull-request with your changes. (Note: Before committing your code please ensure that you are following the Node.js style guide)

Versioning

This package is maintained under the Semantic Versioning guidelines.

License and Warranty

This package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.

lambda-lambda-lambda is provided under the terms of the MIT license

AWS is a registered trademark of Amazon Web Services, Inc.

Author

Marc S. Brooks

Keywords

javascript

FAQs

Package last updated on 11 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts