In the second part of his series comparing CICD services for serverless applications, Erez Rokah, developer of the open source aws-testing-library, focuses on the popular commercial tool, CircleCI.
CircleCI has several main advantages:
Visit part 1 to read about the advantages and disadvantage of using AWS CodeBuild
In this post I’ll show you how to configure an advanced CICD process using CircleCI.
If you don’t have a CircleCI account you should sign up here.
Our goal is to have a CICD setup that will:
In part 1 we used CodeBuild to set up our CICD.
There are a few notable differences between CircleCI and CodeBuild that will affect our setup:
In order to create a reproducible CICD setup, I wrote a small CLI that utilizes the CircleCI API to follow a GitHub project, connect it to AWS, set up all the required environment variables and relevant project settings.
In order to use the CLI you’ll need to create a Personal API Token.
Since I’ve already described our tool stack and prerequisites I won’t repeat them here, but refer back to my previous post for all the details
Run the following command from the
cicd directory to set up the process (replace with the correct values):
yarn setup:circleci --token *********** --stagingAdminEmail
firstname.lastname@example.org --prodAdminEmail email@example.com
setup command will:
Here is a snippet from the
You can see the full command in
trigger:circleci commands to unfollow a project and to trigger a manual build.
After running the
setup command Circle you can visit you CircleCI dashboard to verify the project has been added.
CircleCI config file is under
The file is very similar to our
buildspec.yml from part 1 with the notable difference of the need to handle different deploy stages in the file:
Note that I’m using
yaml aliases to avoid code repetition
The build filters are defined as follows:
The test job will run on pull requests, a
staging deploy will run on merge to master and a
prod deploy will run on tag push (as in part 1).
Build phases, environment variables, build scripts and end to end tests are similar to the ones described in part 1.
The deployment magic happens in the
cicd/scripts/deploy.js script. You can find the code here (I strongly recommend going over it).
Using CircleCI we’ve set up an advanced CICD process for our Serverless application, in a very similar way as we did using CodeBuild in part 1.
While losing the option to use CloudFormation to describe our CICD process in a reproducible way, the CircleCI API is a decent replacement, and by using the AWS SDK we can easily set the proper permissions for our CICD jobs.
The usefulness of a CICD process comes from the ability to monitor errors (e.g. relevant notifications), integrate with other development tools (e.g. Slack), the ability to make changes and resolve issues quickly.
These are all missing from CodeBuild (or require development time and effort) and are included in CircleCI.
If you have questions about replicating this setup, or simply want to talk serverless CICD, get in touch on Twitter.