Implementing CI/CD for Containers on AWS using ECS and CodePipeline

Apply concepts required to automate a CI/CD pipeline

Olawale Olaleye
CloudAdventure
3 min readJun 7, 2019

--

In this article, you will see a demonstration of how to implement a continuous delivery pipeline for microservices using AWS Code Developer tools.

If you work in an agile environment where the capacity to innovate rapidly gives your business a competitive edge, then, orchestrating your deployments with DevOps tools will be a game changer for your deployments.

What’s involved:

  1. AWS CodeCommit — version control system (continuous integration for multiple developers working on same project).
  2. AWS CodeBuild — Build your Docker images
  3. AWS CodeDeploy — automates application deployments to AWS ECS
  4. AWS CodePipeline — continuous delivery service to implement your entire deployment workflow.

Application deployment should be swift and more like just clicking a button. At least, that’s what many Product Managers and Business owners yearn for. Following this guide would make such possible.

In a standard environment, the entire deployment lifecycle of an application is shown in Fig 1.0. All the deployment activities could be automated using AWS CodePipeline.

Fig 1.0 Application Deployment Lifecycle
Fig 2.0 Pipeline Workflow

Let’s get started

Pre-requisites:

A. Your source code including taskdef.json, buildspec.yaml in the root folder.

B. Your running ECS Cluster, ECR, service and task definition.

Initial Step—Go to https://eu-west-1.console.aws.amazon.com/codesuite/home?region=eu-west-1, click Pipeline, create a new project with CodePipeline and give the project a name, such as myfirstpipeline. Choose New Service Role and click Next

Fig 3.0 Pipeline Settings

Step 1 — choose the source location where the code is stored. This could be AWS CodeCommit, GitHub, or Amazon S3. For this example, enter AWS CodeCommit, select Repository name and select branch. Click Next

Fig 4.0 Source

Step 2 — Add a build step. Choose AWS CodeBuild. If you use Jenkins, you can import an existing build, from a Jenkins server URL.

  • Build provider: AWS CodeBuild
  • Create a new build project
  • Environment image: Use an image managed by AWS CodeBuild
  • Operating system: Ubuntu
  • Runtime: Docker
  • Version: aws/codebuild/docker:1.12.1
  • Build specification: Use the buildspec.yml in the source code root directory
Fig 5.0 Build

Step 3 —Add a deployment. Choose AWS ECS. This is the infrastructure where your code will be deployed.

Note: image definition JSON file is needed for CodeBuild to deploy to ECS. Your buildspec.yaml file used for step 2 should include image definition instructions. See sample below;

Fig 6.0 — sample buildspec.yaml

Select region where your cluster is, select Cluster name and service name. Note: The image definition file name must be the exact match of what you specified in buildspec.yaml

Fig 7.0 Deploy

Lastly, review all of your config, and click Create pipeline.

Congratulations!!! Enjoy doing DevOps, enjoy automating.

--

--

Olawale Olaleye
CloudAdventure

DevOps Pro | Cloud Solutions Architect | MultiCloud Specialist