AWS ECS: Terms and Concepts
Tags: aws, cloud, architecture, webdev
Published: 2022-12-15 21:59:21

AWS ECS can be really daunting to grasp at first, mostly because it introduces a lot of new concepts. Without clear analogies, it is hard to understand tutorials explaining all the processes in ECS.

This blog post should serve you as entry point to ECS terms. It should help you understand them and give you examples so you can start learning one of the most valuable AWS services with ease.

## Task Definition

To prepare your application to run on Amazon ECS, you create a task definition. The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application.

It can be thought of as a blueprint for your application. Task definitions specify various parameters for your application. Examples of task definition parameters are which containers to use, which launch type to use, which ports should be opened for your application, and what data volumes should be used with the containers in the task. The specific parameters available for your task definition depend on the needs of your specific application.

Your entire application stack doesn't need to be on a single task definition. You can do this by combining related containers into their own task definitions, each representing a single component.

The following is an example of a task definition containing a single container that runs an NGINX web server using the Fargate launch type.

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

## Task

Task is the instantiation of a task definition. After you create a task definition for your application within Amazon ECS, you can specify the number of tasks to run on your cluster. You can run a standalone task, or you can run a task as part of a service within a cluster. Task can be seen as running container instances.

Cluster and service are ECS terms used to name concepts used for logical grouping of tasks.


![From Task definition to Task](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07vjzne68nmujuomlzjb.png)

## Service

You can use an Amazon ECS *service* to run and maintain your desired number of tasks simultaneously in an Amazon ECS cluster. In case a task fails or stops, service will replace the broken one with the new instance of the same.

Services can be really useful when your apps need maintained availability.

## Containers, Images and AWS ECR

To deploy applications on Amazon ECS, your application components must be configured to run in *containers.* Containers are created from a read-only template that's called an *image.* ECS calls running containers tasks.

Images are typically built from a **Dockerfile**. A Dockerfile is a plaintext file that specifies all of the components that are included in the container. 

After they're built, these images are stored in a *registry* where they can be downloaded from. Most popular one is Dockerhub, but AWS provides such a registry with AWS ECR (Elastic Container Registry). You can upload your images to ECR, then use them to create Task Definitions.


![Image lifecycle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvszzq5iriwawp9km1jf.png)

## Cluster

An Amazon ECS *cluster* is a logical grouping of both tasks or services. You can use clusters to isolate your applications. 

In environments using EC2, clusters are valuable to separate underlying infrastructures, so your apps don’t share them.

On the other hand, if you are using Fargate, your cluster resources are also managed by Fargate.


![Cluster example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eof09w5ulvfyqtio45yp.png)