A serverless microservice template.
- jq - This is a lightweight and flexible command-line JSON processor. This can be installed using
brew install jq - NodeJS - There are two main tools to do this. Please see
.nvmrcfor specific version of Node.- n (Recommended) - This is a node version manager. It allows you to switch between node versions easily.
- Install n using
brew install n - Run
n <version>to use/install the specific version of node
- Install n using
- nvm - This is another node version manager
- Install nvm using
brew install nvm - Run
nvm install <version>to install the specific version of node - Run
nvm use <version>to use the specific version of node
- Install nvm using
- n (Recommended) - This is a node version manager. It allows you to switch between node versions easily.
- NPM (If using n or nvm, your
npmversion will be automatically managed) - Please see
./docker/README.mdfor instructions on how to set up a local MySQL DB using Docker - Security
- Git secrets
- ScanRepo
- Unzip
repo-security-scanner_<version>_Darwin_<architercture>.tar.gzand rename the executable inside the folder toscanrepo- Add executable to path (usingecho $PATHto find your path)
- Unzip
- All serverless functions live in dedicated directories in
src/functions. - Code that is common between multiple functions should reside in
src/common. - Where code is common between services/repos, we have centralised those elements within a common repository.
As per the principles of Hexagonal Architecture, each function has the following directories to help us separate concerns:
framework- entry point for the function, contains the handlerapplication- contains the business logic and data layer accessdomain- contains constants/interfaces/enums for the business logic
Install required dependencies
npm installor
npm iTo clean install, i.e. to rebuild the node_modules folder from scratch based on package-lock.json, run:
npm ciUse the following script to spin up the service locally
npm run startWhen developing locally, we can mock the environment variables to emulate how AWS Lambda would work.
These environment variables can be placed inside a .env file in the root of the project.
As an example, the contents of this file might look like:
ENVIRONMENT=local
HOST=myhost.comA Serverless plugin loads these automatically upon running the start command, and then can be retrieved in the code using
process.env.ENVIRONMENT
process.env.HOSTTo build a zip file for every function to ./artifacts, run:
npm run packageThis is useful for when you want to upload your changes to AWS to test them out on the lambda.
N.b. The build requires jq.
To run the unit tests, simply run:
npm run testTo run unit tests & create code coverage, run:
npm run test:jasmine-coverageThis will produce a ./coverage folder, as well as give the coverage output via your shell.
- This project uses husky to run a series of checks on
pre-commitandpre-push - This project uses
lint-staged,eslintand a strict extended config to enforce code styles