Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Drop-in replacement for Go net/http when running in AWS with ALB and Lambda as target

License

Notifications You must be signed in to change notification settings

TeliaSoneraNorge/alb-gateway

Repository files navigation

Package alb-gateway is based on a fork of Apex/gateway

This package provides a drop-in replacement for net/http's ListenAndServe for use in an AWS Lambda invoked by a ALB Labmda Target Group, simply swap it out for gateway.ListenAndServe.

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/getas/alb-gateway"
	"github.com/aws/aws-lambda-go"
)

func main() {
	http.HandleFunc("/", hello)
	log.Fatal(gateway.ListenAndServe(":3000", nil))
}

func hello(w http.ResponseWriter, r *http.Request) {
	// example retrieving values from the api gateway proxy request context.
	_, ok := gateway.RequestContext(r.Context())
	if !ok {
		fmt.Fprint(w, "Hello World from Go")
		return
	}

	fmt.Fprintf(w, "Hello %s from Go", r.RemoteAddr)
}

About

Drop-in replacement for Go net/http when running in AWS with ALB and Lambda as target

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages