- Go 1.24 or later
- AWS CLI configured
- Required AWS permissions for CloudWatch Logs, KMS, and Config
# Clone the repository
git clone https://github.com/zsoftly/logguardian.git
cd logguardian
# Install dependencies
go mod download
# Run tests
make testThe project uses a comprehensive Makefile for all development tasks:
make build # Build Lambda binary
make package # Create deployment ZIP
make test # Run tests
make test-coverage # Generate coverage report
make clean # Clean build artifactsmake lint # Run linter (uses .golangci.yml)
make security # Run security scan (gosec)
make vuln-check # Check for vulnerabilities
make check # Run all quality checksmake dev-build # Fast build for development
make memory-profile # Memory usage analysis
make cpu-profile # CPU usage analysis
make bench # Run benchmarks
make size # Show binary and package size- Use Go 1.24 (latest stable version)
- Take advantage of new language features
- Follow Go 1.24 best practices
The project enforces strict code quality standards:
- Linting: golangci-lint with comprehensive rule set
- Security: gosec security scanner
- Testing: >90% test coverage required
- Documentation: All public functions documented
- Dependency Injection: AWS clients injected for testability
- Error Handling: All errors explicitly handled
- Context Propagation: context.Context used throughout
- Structured Logging: slog for all logging
- Memory Efficiency: Optimized for Lambda constraints
# Run all tests
make test
# Run tests with race detection
go test -race ./...
# Run specific test
go test -run TestComplianceHandler ./internal/handler- Mock Services: AWS services mocked for unit tests
- Table-Driven Tests: Comprehensive test cases
- Error Testing: Both success and failure paths tested
- Benchmarks: Performance regression prevention
- Minimum 90% test coverage
- All error paths tested
- Edge cases covered
The project uses two main workflows:
-
CI Workflow (
.github/workflows/ci.yml):- Linting and code quality
- Security scanning
- Multi-platform testing
- Lambda function build
- Benchmark testing
-
Release Workflow (
.github/workflows/release.yml):- Automated releases on version tags
- Binary artifacts generation
- Changelog generation
- GitHub release creation
All PRs must pass:
- Linting (golangci-lint)
- Security scanning (gosec, govulncheck)
- Tests on multiple Go versions (1.23, 1.24)
- Tests on multiple platforms (Linux, macOS, Windows)
# Install development tools
make install-tools
# This installs:
# - golangci-lint (linting)
# - gosec (security scanning)
# - govulncheck (vulnerability scanning)
# - mockgen (mock generation)-
Create Feature Branch:
git checkout -b feature/new-feature
-
Make Changes: Follow code standards
-
Test Locally:
make check # Run all quality checks -
Commit Changes:
git commit -m "feat: add new feature" -
Push and Create PR:
git push origin feature/new-feature
# Build development version
make dev-build
# Test with sample event
make test-local# Generate memory profile
make memory-profile
# View profile
go tool pprof mem.prof# Generate CPU profile
make cpu-profile
# View profile
go tool pprof cpu.prof# Set up local AWS credentials
aws configure
# Test AWS connectivity
aws sts get-caller-identity
# Test Lambda deployment
aws lambda update-function-code \
--function-name logguardian-compliance \
--zip-file fileb://dist/logguardian-compliance.zipFor local development, set these environment variables:
export KMS_KEY_ALIAS="alias/cloudwatch-logs-compliance"
export DEFAULT_RETENTION_DAYS="365"
export SUPPORTED_REGIONS="ca-central-1,ca-west-1"
export DRY_RUN="true" # For safe testing├── cmd/lambda/ # Application entry points
├── internal/ # Private application code
│ ├── handler/ # HTTP/event handlers
│ ├── service/ # Business logic
│ └── types/ # Data structures and models
├── testdata/ # Test fixtures and sample data
├── docs/ # Documentation
├── .github/ # GitHub workflows and templates
└── dist/ # Build artifacts (generated)
- cmd/: Application entry points only
- internal/: Private application logic
- internal/handler/: Event processing logic
- internal/service/: Core business logic
- internal/types/: Shared data structures
Follow Go conventions for import grouping:
import (
// Standard library
"context"
"fmt"
"log/slog"
// Third-party packages
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go-v2/config"
// Local packages
"github.com/zsoftly/logguardian/internal/service"
"github.com/zsoftly/logguardian/internal/types"
)- Binary Size: Keep deployment package < 50MB
- Cold Start: Optimize for fast initialization
- Memory Usage: Monitor heap allocation
- Execution Time: Target < 15 minutes
- Client Pooling: Reuse AWS SDK clients
- Buffer Pooling: Reuse byte buffers
- Garbage Collection: Minimize allocations
- Memory Monitoring: Track usage patterns
- Never log sensitive information
- Use context for request cancellation
- Validate all input data
- Handle errors gracefully
- Follow principle of least privilege
- Use customer-managed KMS keys
- Enable CloudTrail logging
- Monitor function metrics
- Build Failures: Check Go version compatibility
- Test Failures: Verify AWS credentials for integration tests
- Lint Errors: Run
make fmtto fix formatting - Memory Issues: Use profiling tools to identify leaks
- Check existing issues on GitHub
- Review logs in CloudWatch
- Use debugging tools for profiling
- Consult AWS documentation for service limits