DEV Community

Cover image for Deploying An Application To Amazon ECS: Everything You Need To Know
Kelvin Onuchukwu
Kelvin Onuchukwu

Posted on

Deploying An Application To Amazon ECS: Everything You Need To Know

Here is a Terraform code that automatically provisions and deploys a production-grade application to an AWS Elastic Container Service(ECS) cluster.

Amazon Elastic Container Service is AWS' native container orchestration service. It is a fully managed service that enables the easy deployment, scaling and management of containerized applications.

ECS Basic Concepts

When working with Amazon ECS, there are a handful of concepts that you must understand in order to get the full picture. A thorough understanding of these concepts is the first step to becoming adept with AWS ECS.

  1. ECS Capacity
  2. ECS Cluster
  3. ECS Task definition
  4. ECS Task
  5. ECS Service
  6. ECS Namespace
  7. ECS Controller
  8. ECS Agent

Now let us explore these concepts one after the other.

- ECS Capacity: ECS capacity refers to the infrastructure on which your containers run. ECS Capacity can be one of the following options:

  • EC2 instances.
  • AWS fargate (serverless).
  • On-premises virtual machines (ECS anywhere).

Similar to ECS capacity is the capacity provier. Amazon ECS cluster capacity providers determine the infrastructure to use for your tasks. Each cluster has one or more capacity providers and an optional default capacity provider strategy. The capacity provider strategy determines how the tasks are spread across the capacity providers.

- ECS Cluster: Th ECS Cluster is a logical grouping of conatiner instances on which the conatainerised applications run. A Cluster can be in one of the following states; ACTIVE, PROVISIONING, DEPROVISIONING, FAILED, INACTIVE.

- ECS Task definition: A task definition is the blueprint for your application. It is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application. Here is a sample below:

{
    "family": "webserver",
    "containerDefinitions": [
        {
            "name": "web",
            "image": "nginx",
            "memory": "100",
            "cpu": "99"
        }
    ],
    "requiresCompatibilities": [
        "FARGATE"
    ],
    "networkMode": "awsvpc",
    "memory": "512",
    "cpu": "256"
}

Enter fullscreen mode Exit fullscreen mode

In many ways it is akin to a docker compose file. Your ECS task definition should contain the following parameters: The launch type, docker image, CPU and memory requirements, operating system of the container instance, docker networking mode, logging configuration, etc.

- ECS Task: An ECS task is an instantiation of a task definition. In other words, it is a running instance of a given task definition. An Elastic Container Service Task consumes resources to run containers based on the configuration in a task definition. Tasks may or may not be long-lived, and expose several attributes to help you monitor their state.
A task can either be in a stopped, active or runnng state.

- ECS Service: A service is a grouping of long-running tasks that share the same task definition. You can use an Amazon ECS service to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. If one of your tasks fails or stops, the Amazon ECS service scheduler launches another instance of your task definition to replace it. This helps maintain your desired number of tasks in the service.

A Service is used to guarantee that you always have some number of Tasks running at all times.
In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.

The image below presents an apt illustration of ECS services and how they fit into the ECS ecosystem.

Image description

- ECS Namespace: A namespace provides a way to organize or group items for purposes of separating the space for different uses or purposes. It allows for the multitenancy feature in ECS. Namespaces are necessary in Amazon ECS to use the ECS Service Connect or ECS service discovery features. Amazon ECS requests namespaces from AWS Cloud Map and then displays your namespaces in the AWS Management Console.

- ECS Controller: The ECS Controller is the Amazon ECS scheduler is the software that manages your applications.

- ECS Agent: The Amazon ECS Container Agent is a component of Amazon Elastic Container Service (Amazon ECS) and is responsible for managing containers on behalf of Amazon ECS.

Conclusion

With these concepts at your fingertips, you can now head into the AWS Console and begin to try out the ECS Service.

Here is a terraform code that automates the provisioning and deployment of a production-grade application to AWS Elastic Container Service.

Connect with me on LinkedIn.

Top comments (1)

Collapse
 
fanki4 profile image
Fanki4

Thank you