A guide to Production Grade ECS Deployment Strategy using AWS Cloudformation Layered Approach

Govind Kumar
axcess.io
Published in
3 min readJan 3, 2023

Amazon Web Services (AWS) supplies a powerful suite of tools for deploying, managing, and scaling applications in the cloud. One of the major services in this suite is Amazon Elastic Container Service (ECS), which makes it easy to deploy, run and manage Docker containers.

Challenges While Deploying the Solution:

In Order to deploy the ECS Solution on AWS, there are certain challenges we face, which include — frequent updates to a few of the components. viz-a-viz —

  • A Complex template (If we keep the Cluster, Task Definition, and Services in the same template)
  • Reusability issue, where — In order to use the same Cluster, we might need to struggle, for each and every solution we need to deploy all the components.
  • Issue while performing the Changes in deployed infrastructure.

Approach

A layered approach in deploying the ECS Solution using Cloudformation involves creating multiple small CloudFormation templates that each manage a specific layer or component of your infrastructure. This allows you to manage your infrastructure as a set of modular, reusable components, making it easier to update and maintain your environment.

The Approach to Solve the Problem:

Here is an example of a layered approach in AWS CloudFormation:

  1. Base Layer(Layer 0): This layer contains the core components of your infrastructure, such as VPCs, subnets and all the other components that we deploy as a one-time solution, or we update once in a blue moon.
  2. Core Service Layer(Layer 1): This layer contains the components that make up your application, such as ECS clusters, IAM Roles, EC2 instances with ASG, an Application load balancer, S3 Bucket, and databases.
  3. Service Addon Layer (layer 2): This layer should consist of various Target Groups specific to various services (eg. If there are 5 Services, which have to be managed by the same Cluster and need to be kept behind the same application load balancer, in such cases, create a Cloudformation template with certain parameters so that the multiple service-specific target groups can be created in a repetitive manner).
  4. Frequently Changed Layer (Layer 3): This layer contains the components that enable you to define the blueprint of your ECS Services which will be provisioned later on. Basically, this layer will be updated every time, whenever there is a new code deployment. You can keep the Task Definition in this layer.
  5. In the end, keep the CICD Pipeline in place to get the latest/stable task definition and update the services to serve the infrastructure with the latest code
A Layered Approach while Designing the ECS-based Solution on AWS Cloud

Outcomes:

The outcome of the above step is a layered approach to deploying the Amazon Elastic Container Service (ECS) solution on Amazon Web Services (AWS) using CloudFormation. This approach solves challenges such as a complex template, reusability issues, and difficulties in performing changes in the deployed infrastructure. The approach involves creating multiple small CloudFormation templates that manage specific components of the infrastructure, making it easier to update and maintain the environment. The four layers include the Base Layer, Core Service Layer, Service Addon Layer, and Frequently Changed Layer. The end result is a streamlined and efficient process for deploying and updating the ECS solution using a CICD pipeline.

Best Practices:

  • Creating multiple small CloudFormation templates that manage a specific layer or component of the infrastructure, allowing for modularity and ease of maintenance.
  • Separating core infrastructure components (such as VPCs, and subnets) into a base layer, and application components (ECS clusters, IAM roles, EC2 instances, etc.) into a core service layer.
  • Creating a separate layer for service-specific target groups.
  • Keeping frequently changed components (such as ECS Task Definitions) in a separate layer for easy updates.
  • Implementing a Continuous Integration and Continuous Deployment (CICD) pipeline to update services with the latest code.

Conclusion:

By using a layered approach in AWS CloudFormation, you can simplify your templates, reduce duplicated code, and manage your infrastructure as a set of modular components, making it easier to update, maintain, and scale your environment.

Knowledge Courtesy: Mr Vikrant Sundriyal (My Mentor).

--

--

Govind Kumar
axcess.io

Technology Evangelist | AWS Golden Jacket | Practice Lead Cloud Migration @Axcess IO | Cloud Arch. | RHC(SA/E) | AWS (DevOps/Sol. Arch) — Pro. | CCNA