2022-12-02

Elastic Container Service (ECS)

What is ECS

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service provided by AWS. In the midst of the growing popularity of microservices architecture, ECS serves as a tool for developers and IT professionals to effectively manage and deploy multiple containers.

Container technology allows packaging applications along with their required runtimes, libraries, and system tools into a single unit. This provides a consistent environment from development to deployment and scaling. However, to effectively manage these containers, appropriate orchestration tools are essential, and this is where ECS plays a crucial role.

Components of ECS

The architecture of ECS is composed of various components that handle the deployment and runtime management of containerized applications.

ECS architecture

Task

In ECS, the execution unit of an application is known as a "Task". A Task is a unit of execution composed of one or more containers, serving as the fundamental unit to launch applications on ECS.

Task Definition

A Task Definition functions as a template for creating and configuring Tasks. This template is described in JSON format and can include details such as which container images to deploy, resource allocation, IAM roles assigned to each task or container, output destinations to CloudWatch Logs, and many other configurations.

A single Task Definition can contain multiple container definitions, enabling effective management of multiple related containers within a single Task.

JSON Sample

json
{
  "family": "my-task-def",
  "networkMode": "awsvpc",
  "requiresCompatibilities": [
    "FARGATE"
  ],
  "cpu": "256",
  "memory": "512",
  "containerDefinitions": [
    {
      "name": "backend",
      "image": "xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/backend:latest",
      "essential": true,
      "portMappings": [
        {
          "hostPort": 8080,
          "protocol": "tcp",
          "containerPort": 8080
        }
      ]
    },
    {
      "name": "frontend",
      "image": "xxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/frontend:latest",
      "essential": true,
      "environment": [],
      "portMappings": [
        {
          "hostPort": 8000,
          "protocol": "tcp",
          "containerPort": 8000
        }
      ],
      "command": [
        "run",
      ]
    }
  ]
}

Service

A Service is a scheduler that maintains a specified number of Tasks, serving as a core component of the orchestrator. When creating a Service, you specify the number of Tasks to launch, associate load balancers, and define the network for running Tasks. If a Task terminates for any reason, a new Task is generated based on the Task Definition to maintain the specified number of Tasks.

Service plays a pivotal role as a core function of orchestration. If a Task terminates for any reason, a new Task is generated based on the Task Definition to maintain the specified number of Tasks. A Service includes settings for related load balancers, network configurations, and the number of Tasks to execute.

Cluster

A Cluster is a logical grouping unit within ECS, designed to manage multiple Services and Tasks. Within a Cluster, you can centrally monitor available resources, Task statuses, and Service statuses.

Data Planes

The Data Plane of ECS collaborates with its components to provide the environment and resources where containers actually operate. AWS offers two Data Plane options:

  • Amazon Elastic Compute Cloud (EC2)
  • AWS Fargate

Amazon Elastic Compute Cloud (EC2)

Amazon EC2 is AWS's virtual private server offering. As part of ECS's Data Plane, EC2 serves as the execution environment for containers. Users can select instance types and resource allocations as needed, and directly launch and manage containers on EC2. Additionally, EC2 easily integrates with a wide range of AWS services, offering high scalability and flexibility in terms of security, networking, and storage.

AWS Fargate

AWS Fargate is a serverless container execution environment, eliminating the need for selecting or managing instances like EC2. Users simply specify containers, and Fargate automatically allocates necessary resources and scales as required. This liberates developers from infrastructure management, allowing them to focus on application code and business logic.

References

https://aws.amazon.com/ecs/

Ryusei Kakujo

researchgatelinkedingithub

Focusing on data science for mobility

Bench Press 100kg!