Go architecture for AWS Lambda
This is the explanation of our file structure:
.
├── domain <-- All domains/entities belong here
├── user <-- Module directory
│ └── handler
│ └── user-get <-- Source code for a lambda function
│ ├── main.go <-- Lambda function code
│ └── main_test.go <-- Unit tests
│ └── repository
│ ├── mysql_repository.go <-- Repository for our db
│ └── mysql_repository_test.go <-- Unit tests
│ └── usecase
│ ├── user_usecase.go <-- Business rules
│ └── user_usecase_test.go <-- Unit tests
│
├── infra <-- All external framework/drivers
├── utils <-- Shared utilities
├── Makefile <-- Make to automate build
└── template.yaml <-- Cloudformation template
make deps
docker-compose up -d
make build
Invoking function locally through local API Gateway
make local
If the previous command ran successfully you should now be able to hit the following local endpoint to invoke your function http://localhost:3000/hello
The following command will package your lambda functions, create a Cloudformation Stack and deploy your SAM resources:
make deploy
After deployment is complete you can run the following command to retrieve the API Gateway Endpoint URL:
make describe
We use testing
package that is built-in in Golang and you can simply run the following command to run our tests:
go test -v ./handlers/hello-world/
For mocking purpose, we use gomock
from Golang to help us to generate mock files quickly.
- Resource tagging