<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anthony Cheng on Medium]]></title>
        <description><![CDATA[Stories by Anthony Cheng on Medium]]></description>
        <link>https://medium.com/@anthony.wan.cheng?source=rss-2f2ddcf57062------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*wwhqpxdHmygXLUV8Ifpsvg.jpeg</url>
            <title>Stories by Anthony Cheng on Medium</title>
            <link>https://medium.com/@anthony.wan.cheng?source=rss-2f2ddcf57062------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:16:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anthony.wan.cheng/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deep Dive into Serverless Infrastructure with CI/CD Workflow — Part 2 (Build environment and…]]></title>
            <link>https://medium.com/@anthony.wan.cheng/deep-dive-into-serverless-infrastructure-with-ci-cd-workflow-part-2-build-environment-and-55a334ef7483?source=rss-2f2ddcf57062------2</link>
            <guid isPermaLink="false">https://medium.com/p/55a334ef7483</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[developerweek]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anthony Cheng]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 18:15:12 GMT</pubDate>
            <atom:updated>2019-06-17T14:13:03.243Z</atom:updated>
            <content:encoded><![CDATA[<h3>Deep Dive into Serverless Infrastructure with CI/CD Workflow — Part 2(Build environment and Serverless setup)</h3><p>Note: This is the second part of a multiple part articles based on my upcoming talk at Developer Week in NYC: “<a href="https://developerweeknewyork2019.sched.com/speaker/anthony_cheng.1zfb27bo">Lessons learned in building CI/CD for Serverless Architectures</a>”. You can view the slide <a href="https://slides.com/anthonyc-1/lessons-learned-in-building-ci-cd-for-serverless-architectures-1">here</a>. You can review part 1 <a href="https://medium.com/@anthony.wan.cheng/deep-dive-into-serverless-infrastructure-with-ci-cd-workflow-part-1-code-repository-setup-999bb88a4b49">here</a>.</p><p>In the 1st part of the article, I briefly went over the high level architecture of my CI/CD pipeline with serverless. A lot of the focus of that article was given to initial git repository setup, which may sometimes be overlooked but has important implications to scalability and re-usability of your CI/CD pipeline for serverless architecture.</p><p>Let’s’ revisit the high level architecture:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*019F-MotoTo5xRHwpBq4Iw.png" /></figure><h3>CI/CD — Build environment</h3><p>I will now focus briefly on the build environment. There are a few common goals that all CI/CD should share, in particularly:</p><ul><li>Build code only once (this ensures consistent build across environment)</li><li>Deploy should be the same to every environment (other than environment variables)</li><li>A broken deployment should never impact production.</li></ul><p>In production, you should almost always has a minimum of at least a development (dev) and production (prod) environment. However, in practice you ideally want a 3rd environment (some call this QA) where one strives to keep a relatively stable development environment. This is especially relevant when you have larger number of developers who are making changes.</p><p>The reason for this is that with constant code changes, it is very likely that your dev environment will be in a constant stage of flux and very often be in a somewhat broken state. This can leave you in a state of inconsistency where multiple developers make changes to dev environment and it becomes more difficult to troubleshoot issues. With a QA environment, one can ensure at least a stable test environment.</p><p>For a more in-depth discussion about CI/CD pattern, take a look at this <a href="https://continuousdelivery.com/implementing/patterns/">article</a>.</p><h3>CI/CD Pipeline Setup</h3><p>I will now go over the Pipeline setup; for this architecture I am using <a href="http://buildkite.com/">Buildkite</a> as my CI/CD. I will assume that some of the <a href="https://buildkite.com/docs/tutorials/getting-started">prerequisites</a> for the pipeline has already been completed.</p><p>One of the primary design goals of our pipeline is that they should be reusable and that almost all our serverless pipelines would look the same (other than specific scenario where something like triggered or dynamic pipelines are required). This is important since we want to follow DRY and minimize issues in our CI/CD setup.</p><p>As a demonstration, here is a simple pipeline for the dev environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*Q6W8fp4rfhFDCkmXhQLTmQ.png" /></figure><p>First note that the demo pipeline for the dev environment is separated into 4 steps: build/test/deploy/push. Note that each step is kept to be as minimal as possible, as most of the complexity should not be at the pipeline level. As noted in the last article, we should strive to minimize incidental complexity.</p><p>In particular, I make heavy use of GNU Make, which is a battle-proven build automation tool that has been heavily used by many open source projects for decades. Because we use Make to handle the variation and complexity, this in turn allows us to be able to re-use the same existing pipeline for different projects.</p><p>As usual for best practices in CI/CD, build, test and deploy are separate. The last step in the dev pipeline is a push step where a successfully tested build is pushed to the docker registry, and subsequent stage(s) (e.g. QA and prod) can simply re-use the docker image. This satisfies the build once part of the requirements that was stated earlier.</p><p>Note: We also put to exclude build for master and QA git branch as these specific git branch will only run in subsequent steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*5n9EsHHKKbuC5f78SnkNaw.png" /><figcaption>QA and Prod stages are similar except you exclude build step</figcaption></figure><p>For the most part, your QA and Prod steps would be somewhat similar to your dev steps with the exception that you generally don’t need or want to (re-)build. Since Serverless Framework compile to Cloudformation on AWS, one can simply re-use the same compiled build. You might also want to add additional testing for both QA and/or Prod as well as potentially extra step like Canary deployment to Production environment as one of the last Prod step.</p><p>While each CI/CD tools have their specific DSL, the important thing is to apply certain best practices in your pipeline.</p><h3>Serverless Setup</h3><p>We will now look at the Serverless setup. One of the key features in Serverless Framework is that it has a very flexible variable system. In particular, you can make use of <a href="https://serverless.com/framework/docs/providers/aws/guide/variables/">optional variable syntax</a>, e.g. <em>${opt:foo, bar}</em>. This allow you to specify optional parameters based on value of an environmental variable, including stage which we use in CI/CD.</p><p>As an example, here is a vanilla boilerplate code for a hello world app. using Serverless framework on AWS:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*6C7EV0HIDxr5PeNmuzTyjQ.png" /></figure><p>One can easily rewrite this YAML file in a parametric format where you would reference another file (dev.yml) based on its stage. In this case, custom section references this file so that by default it would reference <em>dev.yml </em>but you can pass a stage variable to reference another file. For example passing environment variable <em>stage=prod</em> in Serverless would reference <em>prod.yml</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*6_s56mjHoRrFd69EAwYaXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*4mI2WQIrBfZuN3IONLWc_g.png" /></figure><p>By rewriting Serverless configuration this way, one can be simply reuse a default serverless.yml across different CI/CD pipelines; especially since one can reference any other YAML or JSON file as optional file based on environment variables.</p><p>This serves as a starting building block for your Serverless setup within your CI/CD pipeline. In the next article, I will go more in-depth on the consideration on Serverless application in the context of CI/CD, as well as how to leverage both docker-compose and GNU Make for Serverless CI/CD.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55a334ef7483" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep Dive into Serverless Infrastructure with CI/CD Workflow — Part 1 (Code Repository setup)]]></title>
            <link>https://medium.com/@anthony.wan.cheng/deep-dive-into-serverless-infrastructure-with-ci-cd-workflow-part-1-code-repository-setup-999bb88a4b49?source=rss-2f2ddcf57062------2</link>
            <guid isPermaLink="false">https://medium.com/p/999bb88a4b49</guid>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Anthony Cheng]]></dc:creator>
            <pubDate>Sun, 02 Jun 2019 18:41:55 GMT</pubDate>
            <atom:updated>2019-06-16T18:15:59.068Z</atom:updated>
            <content:encoded><![CDATA[<p>Deep Dive into Serverless Infrastructure with CI/CD Workflow — Part 1 (Code Repository setup)</p><p>Note: This is the 1st part of a multiple part articles based on my upcoming talk at Developer Week in NYC: “<a href="https://developerweeknewyork2019.sched.com/speaker/anthony_cheng.1zfb27bo">Lessons learned in building CI/CD for Serverless Architectures</a>”. You can view the slide <a href="https://slides.com/anthonyc-1/lessons-learned-in-building-ci-cd-for-serverless-architectures-1">here</a>. You can view part 2 <a href="https://medium.com/@anthony.wan.cheng/deep-dive-into-serverless-infrastructure-with-ci-cd-workflow-part-2-build-environment-and-55a334ef7483">here</a>.</p><p>When you are ready to start using Serverless/FaaS in production, one of the very first objectives should be integrating the Serverless deployment into your CI/CD Workflow.</p><p>In this article, I will talk about what some of these best practices are when integrating CI/CD workflow for Serverless architecture. I will specifically focus on some specific tools but the overall workflow and principles should generally be applicable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*KRcEB0Un70Zd0Lxk.png" /></figure><h3>Serverless Framework</h3><p>There are a few choices when it comes to choosing a Serverless Framework and also on where to deploy your serverless functions (e.g. a cloud provider or even bare metal on a k8 cluster). This article (<a href="https://lumigo.io/blog/comparison-of-lambda-deployment-frameworks/">https://lumigo.io/blog/comparison-of-lambda-deployment-frameworks/</a>) gave a very good overview of the different type of serverless framework available.</p><p>In this article, I will deploy my serverless functions in AWS and my framework of choice is Serverless Framework. I’d highly recommend using a framework (versus not using one), as using a good framework will greatly help in reducing the amount of time for setup and deployment.</p><h3>Continuous Integration/Continuous Delivery</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*VpFtfG4DB4gL5AF32NEfSQ.png" /><figcaption>Ref. <a href="https://www.atlassian.com/continuous-delivery/continuous-deployment">https://www.atlassian.com/continuous-delivery/continuous-deployment</a></figcaption></figure><p>At my current company, we use <a href="http://www.buildkite.com/">Buildkite</a> for both our CI/CD. Buildkite differs somewhat from some of the other CI/CD tools in that you run your own build agents. While this means you’d have to be responsible for the build agent, it also gives you full control of the build agent. For example when troubleshooting, you have the option to login to the build agent to troubleshoot directly, which can be extremely helpful.</p><h3>CI/CD Pipeline</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*019F-MotoTo5xRHwpBq4Iw.png" /></figure><p>The design goal of a good CI/CD system should be reusable and scalable, and easy to troubleshoot when things break. One should keep <a href="https://pressupinc.com/blog/2014/05/root-causes-software-complexity/">incidental complexity</a> at a minimal for a CI/CD system as its goal is to simply integrate, test and deploy code.</p><p>Here are some of my recommendations in setting up different parts of a CI/CD system:</p><ol><li>Git repository setup</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/0*q6G3tXQoEYkh8wIl.png" /></figure><p>I recommend that serverless code be setup as a multi repository (as opposed to a mono repo setup). First of all, this fits in with the paradigm of a microservice architecture. In fact, I’d argue mono repo is anti-pattern. Moreover; for serverless architecture we can organize multiple functions in multiple serverless application with docker-compose (more on this later).</p><p>Multiple repo are easier to scale as your code base get larger. It also reduces complexity since you can quickly see the purpose of a repo. For serverless architecture, ideally each lambda follow the single responsibility principle (SRP). This article (<a href="https://theburningmonk.com/2018/01/aws-lambda-should-you-have-few-monolithic-functions-or-many-single-purposed-functions/">https://theburningmonk.com/2018/01/aws-lambda-should-you-have-few-monolithic-functions-or-many-single-purposed-functions/</a>) articulates why single-purposed functions are better suited when it comes to debugging, discoverability, and scalability.</p><p>Furthermore, if you are lambdas are constructed according to SRP, then it becomes much easier to construct your overall serverless application (including not only lambdas) to also be reusable. Also in the context of CI/CD, have smaller serverless application will both reduce the speed of the build and deployment. This is especially relevant for AWS; as many different serverless framework uses Cloudformation under the hood as their IaC and Cloudformation is not particular fast nor it is truly idempotent. This means you should be mindful when constructing your serverless application so that its ‘blast radius’ should be as minimal as possible, given that you may find yourself having to re-deploy or even delete the underlying Cloudformation stack.</p><p>In Part 2, I will go over the build environment and serverless framework setup.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=999bb88a4b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>