Oct 10, 2017
[archived]

TL;DR

You can clone or download the template for my github repository: Lambda Serverless CI/CD

Motivation

Serverless application using AWS lambda let you run code without provisioning or managing servers [AWS Lambda].

Not having to provision or manage servers doesn’t imply that you can fire your DevOps team. It merely means that some aspects of running your application lifecycle got a little bit easier, but you still need to think about how to manage and operate serverless applications.

Two years ago we didn’t have the ecosystem of tools that we have nowadays. I specifically talk about the Serverless Framework.

With the Serverless Framework, you can quickly setup and deploy a serverless application, but that is as far as serverless go, you still need to think about building, packaging, and continuously integrate and deploying the application. CI/CD pipeline

I have created a sample CloudFormation template that generates a CI/CD pipeline using AWS CodePipeline and AWS CodeBuild. It deploys a lambda functions to a staging environment. After an approval step the function is deployed to a pducttion environment. These are the steps in more detail:

  1. Deploy the application to a staging environment
    • Install and package dependencies
    • Deploy using the serverless framework
  2. Approval process
    • User must manually approve the deployment to production (ideally after staging has been tested)
  3. Deploy the application to a production environment
    • Install and package dependencies
    • Deploy using the serverless framework

Each deployment process runs on CodeBuild, and you can select the docker image that it uses for the build process. By default it runs a custom image that I have created which is a wrapper of the Amazon Linux 2017.09 image, it has pre-installed nodejs 8.8, python3.6, numpy and pandas. While this is an image aims at data science applications, it can be used to create any python3.6 applications.

To get started with the template all you have to do is:

  1. Copy the buildspec.yml and deploy.sh files to the root of your repository
  2. Create the cloud formation stack and plug in the given parameters for your repository using the serverless-codepipeline-cicd_cfm.yml CloudFormation template
  3. Your repo must contain a valid serverless.yml in the root of the project

In the future, I am planning to add more deployment strategies to be able to compile, package and deploy Scala, and .NETCore apps.