Example CI/CD pipeline for Serverless framework based on GitLab.
- Linting
- Unit testing
- e2e testing against deployed APIs
- Multiple environment dev, staging, live
- Dev environments deployed per branch
- Destroy old environments via the Operations > Environments
- Security dependency scanning
- Static application security testing
- Test coverage metrics
- Monitoring
- Middy middleware for input validation and helpers
You need to build the docker image if you don't want to use the default
- check the registry tab in the project on GitLab for instructions
Requires environmental variables from IAM user created for deployments:
- AWS_ACCESS_KEY_ID with the new user’s access key
- AWS_SECRET_ACCESS_KEY with the new user’s access secret key
Requires environmental variable for monitoring (Other solutions possible as they use a similar method of being configured in the serverless.yml file)
- IOPIPE_TOKEN
- Disable committing to master and only allow changes by merging via branches
Prereq:
Make sure you have these two installed before you start.
nodejs
yarn
You also needserverless installed.
yarn global add serverless
Install:
yarn install
Run unit tests:
yarn unit
Run linting and auto correct errors:
yarn lint
Version bump
yarn upgrade --latest
Dry run of a deploy, useful for finding errors:
sls deploy -s dev -v --noDeploy
Deploy to the environment at the stage dev:
sls deploy -s dev
Shutdown the environment at the stage dev
sls remove -s dev
Build a webpack complied version into the dist folder but do nothing with it, useful for debugging webpack issues and checking builds are correct:
sls webpack -out dist
Get cloudwatch logs via command line for a specific function:
sls logs -f featureOne -s dev
If you want to run builds locally to test you need to configure environmental variables for DYNAMODB_TABLE_NAME and IOPIPE_TOKEN
export DYNAMODB_TABLE_NAME=AnyTableName
export IOPIPE_TOKEN=DoesNotHaveToBeValidUnlessDeploying
Note: On the todo list to improve handling of configuration variables
Main purpose of this was to try and setup a fairly feature complete serverless CI/CD pipeline for GitLab, however, there is still a lot of room for improvement.
Feel free.