How awslabs/aws-lambda-go-api-proxy works
Project type and purpose
• This is an open-source Go library (“aws-lambda-go-api-proxy”) that provides adapter layers to run Go HTTP frameworks (Gin, Fiber, Chi, Echo, GorillaMux, Negroni, plain http.HandlerFunc) as AWS Lambda functions behind API Gateway.
File structure
• Top-level:
• core/ ← central converter logic
• [framework]/ ← one directory per supported framework (gin/, fiber/, echo/, chi/, gorillamux/, negroni/, handlerfunc/, httpadapter/)
• examples/ ← full examples (e.g., fiber)
• sample/ ← deployable SAM application
• Makefile, CI configs, README, LICENSE, etc.
• core/ contains request.go, response.go, types.go, plus ALB and v2 variants: implements RequestAccessor → ProxyEventToHTTPRequest() and ProxyResponseWriter → GetProxyResponse().
• Each framework dir contains an adapter.go implementing the adapter type (e.g., GinLambda) by embedding core.RequestAccessor and wiring up the framework’s engine.
• sample/ holds a CloudFormation/SAM template and a Go main.go showing how to wire up one adapter into a real Lambda function.
Key insights from README
• Shows call flow: API Gateway → Lambda handler → adapter.ProxyWithContext → core.ProxyEventToHTTPRequest → framework ServeHTTP → core.ProxyResponseWriter → API Gateway response.
• Emphasizes the Adapter Pattern: each framework adapter uses the same core interfaces and conversion logic.
• Explains supported Lambda payload variants (ALB events, v2 payloads, etc).
Main components
a. AWS API Gateway
b. AWS Lambda Runtime
c. Adapter Layer (per framework):
• HTTPAdapter (stdlib)
• GinLambda
• FiberLambda
• ChiLambda, etc.
d. Core Conversion Module
• RequestAccessor (ProxyEventToHTTPRequest)
• ProxyResponseWriter (GetProxyResponse)
e. Underlying Go HTTP Framework (Gin Engine, Fiber App, etc.)
f. User’s HTTP Handlers (business logic in Gin routes, Fiber handlers, etc.)
g. AWS CloudWatch Logs (optional)
h. Sample SAM Deployment (CloudFormation)
Relationships and interactions
1. API Gateway forwards incoming HTTP request as APIGatewayProxyRequest →
2. Lambda Runtime invokes Handler (generated by adapter).
3. Adapter receives (ctx, APIGatewayProxyRequest) → calls core.RequestAccessor.ProxyEventToHTTPRequest → produces http.Request.
4. Adapter creates core.ProxyResponseWriter, then calls frameworkEngine.ServeHTTP(responseWriter, request).
5. FrameworkEngine dispatches to user-defined HTTP routes/handlers → writes to responseWriter.
6. After ServeHTTP returns, adapter calls responseWriter.GetProxyResponse() → APIGatewayProxyResponse.
7. Lambda returns that to API Gateway → client receives HTTP response.
8. Throughout, logs flow to CloudWatch.
Architectural patterns and design principles
• Adapter Pattern: each framework adapter implements the same interface by embedding core conversion logic.
• Single Responsibility: core only handles event ↔ HTTP conversion; adapters only hook up frameworks.
• Layered design: AWS infra → Lambda runtime → adapter → core → framework → user code.
Technologies, frameworks, libraries
• Go standard library (net/http)
• AWS Lambda Go SDK (github.com/aws/aws-lambda-go/events, lambda)
• Core module (in-repo)
• Supported frameworks: Gin, Fiber, Echo, Chi, GorillaMux, Negroni, HandlerFunc
• AWS SAM (sample/sam.yaml)
• CloudFormation, AWS CLI for deployment
Elements
• Clear labels: “API Gateway”, “Lambda Runtime Handler”, “Core: RequestAccessor”, “Core: ProxyResponseWriter”, “Gin Engine”, “User Handler”, etc.