npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

http-lambda-proxy

v1.1.4

Published

Proxy HTTP requests to AWS Lambda

Downloads

86

Readme

http-lambda-proxy

Node.js library that allows to proxy HTTP requests to AWS Lambda functions. The goal is to empower developers to consider step by step migration of endpoints/workflows and even fully featured HTTP/REST services into serverless.

What is AWS Lambda?

AWS Lambda

Install

npm i http-lambda-proxy

Usage

The following example describe how to use http-lambda-proxy with restana:

const lambdaProxy = require('http-lambda-proxy')
const proxy = lambdaProxy({
  target: process.env.FUNCTION_NAME,
  region: process.env.AWS_REGION
})

const service = require('restana')()
service.all('/*', (req, res) => { 
  proxy(req, res, req.url, {}))
}) 

service.start(8080)

In this example, we proxy all http requests on port 8080 to an AWS Lambda function.

Example lambda function implementation:

const serverless = require('serverless-http')
const json = require('serverless-json-parser')
const query = require('connect-query')

const service = require('restana')()
service.use(query())
service.use(json())

// routes
service.get('/get', (req, res) => {
  res.send({ msg: 'Go Serverless!' })
})
service.post('/post', (req, res) => {
  res.send(req.body)
})

// export handler
module.exports.handler = serverless(service)

API

Options

region *

Set the AWS Region of the target downstream lambda.

target *

AWS Lambda funcion name, version, or alias.

logType

Set to "Tail" to include the execution log in the response. Default: "None"

qualifier

Specify a version or alias to invoke a published version of the function.

clientContext

Up to 3583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.

lambdaProxy

Function wrapper to AWS Lambda invocation proxy. Allows to overwrite default implementation.

Any other AWS.Lambda constructor option is allowed: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html


More details on aws-sdk / lambda / invoke: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property

Proxying

proxy(
  originReq,                          // http.IncomingMessage 
  originRes,                          // http.ServerResponse
  req.url,                            // Request URL
  {}                                  // Options described below
)

Options

onResponse(req, res, response)

Called when the remote lambda response is received. If defined, default behavior is overwritten.

rewriteHeaders(headers)

Called to rewrite the headers of the response, before them being copied over to the outer response. It must return the new headers object.

Supported response formats

The following alternatives describe the supported response formats:

  • Ideally, your lambda function is implemented using the serverless-http module, so you can run fully featured Node.js REST/HTTP services as AWS Lambda funtions.
  • Your lambda respond using a JSON Payload with the following format:
    {
      "headers": {
        // ...
      },
      "statusCode": 200,
      "body": // ...
    }
  • Your lambda respond with a JSON Payload and it contains a body property:
    exports.handler = async function () {
      return JSON.stringify({
        body: "Hello World!"
      })
    }

The lambda function implementation is NOT restricted to Node.js, you can use any of the supported AWS Lambda runtimes.

Related topics

  • fast-gateway: https://www.npmjs.com/package/fast-gateway
  • fast-proxy: https://www.npmjs.com/package/fast-proxy

License

MIT

Sponsors

  • (INACTIVE) Kindly sponsored by ShareNow, a company that promotes innovation!

Support / Donate 💚

You can support the maintenance of this project:

  • Paypal: https://www.paypal.me/kyberneees
  • NANO Crypto Coin: nano_3zm9steh8mb374f8be3rbytqhgzzarczhwtxhihkqt83a4m46oa3xidfiauc
  • XRP Crypto Coin: rarQgNuiqF9gFLLwd5fdku4jYa9EXpiyCp
  • TRON Crypto Coin: TJ5Bbf9v4kpptnRsePXYDvnYcYrS5Tyxus
  • BITCOIN Crypto Coin: bc1qcrr58venyh54ztvkqym39p9rhnxg4308t0802f
  • Ethereum Crypto Coin: 0xD73c8E63a83eBD8Df3fB3d0090f1fe7a1eEB980B