Overview
- Purpose: Gin-based AWS Lambda API, inspired by
nexus-iban-client-lambda. - Modes: Local Gin server (no SAM), and Lambda via the Gin adapter.
Run Locally (no SAM)
- Prereqs: Go 1.24+,
go mod downloadto fetch deps. - Recommended:
make run(usesrun-local.shto free the port before start). - Alternatives:
bash ./run-local.shgo run ./local-main.go
- Env:
PORT(default 3000),LOG_LEVEL(default info),ENV(default local) - Custom port:
PORT=4000 make run - URLs:
http://localhost:3000/healthz,http://localhost:3000/readyz,http://localhost:3000/v1/hello/world - Note:
run-local.shwill trylsof/fuser/ssto kill any process listening onPORTbefore launching.
Environment (.env files)
- Files:
.env(base),.env.local(machine overrides) - Local loader: automatically loads
.env, then overrides with.env.local - Variables:
ENV: runtime environment, defaultlocalPORT: HTTP port for local server, default3000LOG_LEVEL:debug|info|warn|error, defaultinfoAWS_REGION: region for AWS clients, defaulteu-west-3
- Customize: copy
.env.exampleto.env, then tweak. Optionally create.env.localto override on your machine.
Build For Lambda
- Build tag:
lambda(seebuild_constraints.go). - Binary:
bootstrapforprovided.al2runtime, ARM64. - Example:
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build -tags lambda -ldflags="-s -w" -o bootstrap ./main.go - Package:
zip function.zip bootstrapormake package.
Project Layout
main.go: Lambda entrypoint usingaws-lambda-go-api-proxy/gin(build taglambda).local-main.go: Local Gin server (no SAM needed; build tag!lambda).internal/router: Gin engine and routes.internal/handlers: Handlers (/healthz,/readyz,/v1/*).internal/middleware:CORS,RequestID,Logger.internal/config: Env loading (port, env, log level).template.yaml: SAM template (proxy all routes; runtime provided.al2).buildspec.yaml: CodeBuild pipeline (builds./main.go).
Dependencies
github.com/gin-gonic/gin: Web framework.github.com/aws/aws-lambda-go: Lambda types and bootstrap.github.com/awslabs/aws-lambda-go-api-proxy/gin: Adapter for API Gateway → Gin.
Next Steps
- Add your domain routes under
router.New()or split into packages (handlers,services,models). - If mirroring the reference repo further, add middleware, utils, and database layers similarly.