aws-lambda-go-adapter

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2022 License: MIT

README

aws-lambda-go-adapter

Simple adapter for using net/http http.Handler with AWS Lambda.

Supports:

  • AWS Lambda Function URL
  • API Gateway (v1)
  • API Gateway (v2)

Example

package main

import (
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/its-felix/aws-lambda-go-adapter/httpadapter"
	"net/http"
)

func main() {
	mux := http.NewServeMux()
	mux.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusOK)
		_, _ = w.Write([]byte("pong"))
	})

	adapter := httpadapter.NewVanillaAdapter(mux)
	handler := httpadapter.NewFunctionURLHandler(adapter)

	lambda.Start(handler)
}

Extending for other frameworks

To extend this for other frameworks, you'd have to implement a new Adapter.

The adapter is responsible to translate from and to a generic http interface provided by the handler of your choice.

To get an idea, have a look at the vanilla adapter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL