This template enables you to write AWS Lambda Functions in Go, while sharing packages between lambdas without hosting each package/lambda in its own seperate repository.
Containing multiple packages within a single repository is known as a Monorepo. This model is appropriate for users happy to trade-off package versioning for the gain of tighter development cycles. Other pros/cons of Monorepos can be found here.
Having setup such an environment for Credit Companion, I thought others may benefit from it.
Where the serverless functions that are declared in functions/ are deployed to.
A friendlier C with much of the power for writing our functions.
Deployment tool which, for us, streamlines deploying code as a Lambda in AWS. Configurable with serverless.yml.
CI steps triggered on each push to run all tests in the project. Configurable with .github/workflows/go.yml.
To support Serverless and for easier scripting.
go.mod files do not support string building, thus linking local modules at build time is not possible from a root directory.
To circument this, as can be seen in build.sh, we must cd into each function/package and build in turn.
Each package under this directory must contain a main.go, which acts as the entrypoint for that lambda. Any code that you wish to share between lambdas should be moved to packages/.
To add a local package to a function, see the replace line in functions/hello/go.mod.
All shared code should be written here. Each package must contain its own mod.go to declare its namespace.
- NVM
- An AWS account
- AWS CLI configured with access to your AWS account
- Go
For first time setup, run the following within the project root:
nvm use
npm install -g yarn
yarn installTo build the binaries for each function under functions/, run the following from anywhere in the repo:
yarn buildTo run all tests under functions/ and packages/, run the following from anywhere in the repo:
yarn testTo deploy your built binaries to AWS, run the following:
yarn deployThe hello function is a modified version of the Serverless Hello World example.
logger.go is lifted from Chip Keyes' excellent article on Medium.