• Stars
    star
    1,735
  • Rank 26,854 (Top 0.6 %)
  • Language
    JavaScript
  • License
    Other
  • Created about 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use your existing middleware framework (e.g. Express, Koa) in AWS Lambda πŸŽ‰

serverless-http

Build Status

Description

This module allows you to 'wrap' your API for serverless use. No HTTP server, no ports or sockets. Just your code in the same execution pipeline you are already familiar with.

Sponsors

Thank you to Upstash for reaching out to sponsor this project!

Upstash

Upstash: Serverless Database for Redis

  • Serverless Redis with global replication and durable storage
  • Price scales to zero with per request pricing
  • Built-in REST API designed for serverless and edge functions

Start for free in 30 seconds!

Support

Supported Frameworks

(* Experimental)

  • Node (http.createServer)
  • Connect
  • Express
  • Koa
  • Restana
  • Sails *
  • Hapi *
  • Fastify *
  • Restify *
  • Polka *
  • Loopback *

Supported Providers

  • AWS
  • Azure (Experimental, untested, probably outdated)

Examples

Please check the examples folder!

Usage example using the Koa framework

const serverless = require('serverless-http');
const Koa = require('koa'); // or any supported framework

const app = new Koa();

app.use(/* register your middleware as normal */);

// this is it!
module.exports.handler = serverless(app);

// or as a promise
const handler = serverless(app);
module.exports.handler = async (event, context) => {
  // you can do other things here
  const result = await handler(event, context);
  // and here
  return result;
};

Usage example using the Express framework with Azure

const serverless = require('serverless-http');
const express = require('express');

const app = express();

app.use(/* register your middleware as normal */);

const handler = serverless(app, { provider: 'azure' });
module.exports.funcName = async (context, req) => {
  context.res = await handler(context, req);
}

Other examples

json-server-less-Ξ» - using serverless-http with json-server and serverless framework in AWS

Limitations

Your code is running in a serverless environment. You cannot rely on your server being 'up' in the sense that you can/should not use in-memory sessions, web sockets, etc. You are also subject to provider specific restrictions on request/response size, duration, etc.

Think of this as a familiar way of expressing your app logic, not trying to make serverless do something it cannot.

Contributing

Pull requests are welcome! Especially test scenarios for different situations and configurations.

Further Reading

Here are some more detailed examples and advanced configuration options as well as provider-specific documentation

More Repositories

1

serverless-plugin-split-stacks

A plugin to generate nested stacks to get around CloudFormation resource/parameter/output limits
JavaScript
282
star
2

serverless-plugin-include-dependencies

JavaScript
181
star
3

angular-img-http-src

JavaScript
42
star
4

serverless-plugin-custom-domain

Add API Gateway Custom Domain BasePathMappings reliably
JavaScript
40
star
5

serverless-plugin-log-subscription

JavaScript
38
star
6

serverless-plugin-common-excludes

Exclude common things from your Serverless package
JavaScript
35
star
7

serverless-plugin-bootstrap

Checks that the environment around your Serverless service has been set up and is up-to-date
JavaScript
11
star
8

add-custom-resource

JavaScript
7
star
9

tf-output

Obtain terraform outputs
JavaScript
7
star
10

angularjs-templates-brunch

Compile templates in to an AngularJS module as a Brunch plugin
CoffeeScript
5
star
11

circleci-sonar-scanner-docker

Shell
5
star
12

dread-node

yet another retry library
JavaScript
4
star
13

serverless-plugin-common-layers

JavaScript
4
star
14

haproxy-docker-gen

Shell
3
star
15

github-webhooks-kinesis

Send GitHub Webhooks to Kinesis!
JavaScript
3
star
16

aws-info-node

Get info about AWS Services and Regions
JavaScript
2
star
17

aws-apigateway-caching

this appears to be a bug with the way API gateway handles per-method settings
2
star
18

get-openapi-paths

Infer an OpenAPI paths-like object from various web frameworks
JavaScript
2
star
19

mobgoose

Manage and reuse mongoose connections
JavaScript
2
star
20

fauxerhose

Like Kinesis Firehose, but with more control.
JavaScript
2
star
21

aws-streams-node

Stream-like interfaces to the aws-sdk
JavaScript
2
star
22

stream-batches

JavaScript
1
star
23

serverless-plugin-kinesis-consumer

Subscribe Lambda to Kinesis using enhanced fan-out
JavaScript
1
star
24

lamberjack

Ship CloudWatch Logs to Firehose!
JavaScript
1
star
25

superclient

Create fluent interfaces for talking to an API
JavaScript
1
star
26

fauxerhose-transform-cloudwatch

Transformation middleware for fauxerhose that unzips/parses CloudWatch Logs
JavaScript
1
star