• Stars
    star
    652
  • Rank 69,062 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 2 years ago

Reviews

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

Repository Details

Drop-in replacement for Go net/http when running in AWS Lambda & API Gateway

Package gateway provides a drop-in replacement for net/http's ListenAndServe for use in AWS Lambda & API Gateway, simply swap it out for gateway.ListenAndServe. Extracted from Up which provides additional middleware features and operational functionality.

There are two versions of this library, version 1.x supports AWS API Gateway 1.0 events used by the original REST APIs, and 2.x which supports 2.0 events used by the HTTP APIs. For more information on the options read Choosing between HTTP APIs and REST APIs on the AWS documentation website.

Installation

To install version 1.x for REST APIs.

go get github.com/apex/gateway

To install version 2.x for HTTP APIs.

go get github.com/apex/gateway/v2

Example

package main

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

	"github.com/apex/gateway"
)

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.
	requestContext, ok := gateway.RequestContext(r.Context())
	if !ok || requestContext.Authorizer["sub"] == nil {
		fmt.Fprint(w, "Hello World from Go")
		return
	}

	userID := requestContext.Authorizer["sub"].(string)
	fmt.Fprintf(w, "Hello %s from Go", userID)
}

GoDoc

More Repositories

1

up

Deploy infinitely scalable serverless apps, apis, and sites in seconds to AWS.
Go
8,780
star
2

gh-polls

Polls for user feedback in GitHub issues
Go
1,762
star
3

log

Structured logging package for Go.
Go
1,362
star
4

apex-ui

Apex monochrome Atom theme UI.
CSS
412
star
5

up-examples

Example apps, apis, and sites for Up.
HTML
389
star
6

static

The static site anti-framework – general-purpose library, purpose-built commands for various domains
Go
293
star
7

apex-go

Golang runtime for Apex/Lambda.
Go
293
star
8

node-apex

Node.js module that makes AWS Lambda's user experience a little nicer using promises.
JavaScript
279
star
9

rpc

Simple RPC style APIs with generated clients & servers.
Go
215
star
10

actions

GitHub Actions
Go
176
star
11

gui

GitHub readme UI components
CSS
132
star
12

apex-syntax

Apex monochrome Atom theme syntax.
CSS
128
star
13

apex-shell

Interactive shell for executing commands in AWS Lambda containers.
Go
121
star
14

capture

Lambda function to capture a URL as PNG, JPG, or GIF using PhantomJS
JavaScript
108
star
15

httpstat

Higher level HTTP tracing for Go
Go
96
star
16

js

Go packages for JavaScript WASM interoperability in the browser
Go
90
star
17

apex-ui-slim

Apex monochrome Atom theme UI (slim variant)
CSS
74
star
18

svg_to_png

Lambda function to convert SVG to PNG using PhantomJS
JavaScript
71
star
19

logs

Apex Logs client for Go.
Go
61
star
20

apex.run

Apex website
HTML
58
star
21

up.js

Up application companion library for Node and the browser
JavaScript
58
star
22

logs-js

Apex Logs client for Node, Deno, and the browser
TypeScript
38
star
23

logs-cloudwatch

Send your AWS CloudWatch Logs to Apex Logs.
Go
38
star
24

httplog

Go http logger for apex/log.
Go
35
star
25

parsers

Performant Go log format parsers.
Go
31
star
26

apex

Old apex/apex
Go
31
star
27

roadmap

Roadmap for Apex Software products
30
star
28

invoke

Lambda invocation helper functions for Go.
Go
27
star
29

logs-winston

Apex Logs integration for the Node.js Winston logging framework
JavaScript
23
star