A production-ready Go template for AWS Lambda functions with comprehensive tooling, testing, and CI/CD pipelines.
- π AWS Lambda Ready: Pre-configured for AWS Lambda deployment with custom runtime
- π οΈ Modern Tooling: golangci-lint, gofmt, lefthook for code quality
- π§ͺ Testing: Built-in test infrastructure with coverage reporting
- π¦ CI/CD: GitHub Actions workflows for testing, security scanning, and deployment
- π Security: Integrated gosec, govulncheck, and CodeQL scanning
- π Documentation: Comprehensive development and deployment guides
- Go: 1.24 or higher
- Git: 2.30 or higher
- AWS CLI: Configured with appropriate credentials
- Terraform: 1.10 or higher (for infrastructure deployment)
-
Clone the repository:
git clone https://github.com/riyanimam/go-lambda-template.git cd go-lambda-template -
Install dependencies:
go mod download
-
Set up Git hooks (optional but recommended):
# Install lefthook go install github.com/evilmartians/lefthook@latest # Install hooks lefthook install
-
Build the function:
go build -o bootstrap ./src/main.go
-
Run tests:
go test -v ./... -
Run tests with coverage:
go test -v -race -coverprofile=coverage.out ./... go tool cover -html=coverage.out -
Lint code:
# Install golangci-lint go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest # Run linter golangci-lint run ./...
-
Format code:
gofmt -l -s -w .
Build the Lambda function for deployment:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -tags lambda.norpc -ldflags="-s -w" -o bootstrap ./src/main.go
zip lambda-function.zip bootstrapThe -ldflags="-s -w" flags reduce the binary size by removing debug information and symbol tables.
Deploy using Terraform:
cd terraform
terraform init
terraform plan
terraform applySee terraform/README.md for detailed deployment instructions.
.
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD workflows
βββ src/
β βββ main.go # Lambda handler implementation
β βββ main_test.go # Handler tests
βββ terraform/ # Infrastructure as Code
βββ .golangci.yml # golangci-lint configuration
βββ lefthook.yml # Git hooks configuration
βββ go.mod # Go module dependencies
βββ README.md # This file
| Command | Description |
|---|---|
go build -o bootstrap ./src/main.go |
Build the Lambda function |
go test -v ./... |
Run all tests |
go test -v -race -coverprofile=coverage.out ./... |
Run tests with race detection and coverage |
golangci-lint run ./... |
Run comprehensive linting |
gofmt -l -s -w . |
Format all Go code |
go mod tidy |
Update dependencies |
lefthook run pre-commit |
Run pre-commit hooks manually |
This template includes comprehensive GitHub Actions workflows:
- CI: Multi-version testing (Go 1.22.x, 1.23.x) and artifact building
- Code Quality: Linting, formatting checks, and test coverage
- Security: gosec, govulncheck, and CodeQL scanning
- PR Validation: Conventional commit message validation
Contributions are welcome! Please see DEVELOPMENT.md for development guidelines.
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For questions or issues:
- Open an issue on GitHub
- Review the DEVELOPMENT.md guide
- Check existing issues and discussions