Skip to content

Go net/http adaptor for AWS Lambda with ALB or API Gateway

License

Notifications You must be signed in to change notification settings

yacchi/lambda-http-adaptor

Repository files navigation

lambda-http-adaptor

Go Reference GitHub

lambda-http-adaptor is a compatible adaptor for Go net/http that can be used in multiple serverless environments.

You can run your existing http.HandlerFunc compatible web application on AWS Lambda or Azure Functions.

Example

lambda-http-adaptor provides the adaptor.ListenAndServe method, which can drop-in replacement for the http.ListenAndServe.

package main

import (
	"github.com/yacchi/lambda-http-adaptor"
	_ "github.com/yacchi/lambda-http-adaptor/all"
	"log"
	"net/http"
)

func main() {
	log.Fatalln(adaptor.ListenAndServe("", http.HandlerFunc(echoReplyHandler)))
}

func echoReplyHandler(w http.ResponseWriter, r *http.Request) {
	m := r.URL.Query().Get("message")
	w.Header().Set("Content-Type", "text/plain")
	w.Write([]byte(m))
}

Features

  • AWS Lambda support
    • API Gateway REST API integration
      • Multi-value headers
      • Multi-value query string
      • Get ProxyRequestContext value from Context
    • API Gateway HTTP API integration
      • Multi-value headers
      • Get V2 HTTPRequestContext value from Context
    • Application Load Balancer Lambda target
      • Multi-value headers
      • Get ALBTargetGroupRequestContext value from Context
    • Get raw request value from Context
    • Lambda container image function
    • API Gateway Websocket API integration (Experimental)
  • AWS API Gateway utilities
    • Strip stage var middleware
    • Abstract interface of RequestContext
  • Azure Functions support
    • HTTP Trigger with custom handler