Skip to content

A template repository for a monorepo that deploys AWS Lambdas written in Go using Serverless.

License

Notifications You must be signed in to change notification settings

tjmgregory/aws-lambda-go-monorepo

Repository files navigation

AWS Lambda Go Monorepo Template 🚝

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.

What does each part of this template do?

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.

functions/

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.

packages/

All shared code should be written here. Each package must contain its own mod.go to declare its namespace.

Setup

Requirements

For first time setup, run the following within the project root:

nvm use
npm install -g yarn
yarn install

Build and deployment

To build the binaries for each function under functions/, run the following from anywhere in the repo:

yarn build

To run all tests under functions/ and packages/, run the following from anywhere in the repo:

yarn test

To deploy your built binaries to AWS, run the following:

yarn deploy

Credits

The hello function is a modified version of the Serverless Hello World example.

logger.go is lifted from Chip Keyes' excellent article on Medium.

About

A template repository for a monorepo that deploys AWS Lambdas written in Go using Serverless.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published