AWS ECS is a container service provided by AWS. AWS ECS simplifies the deployment, management, and scaling of containerized applications.
Components of ECS :
Clusters - Clusters are grouping of EC2 instances or Fargate on which the containers are deployed.
Task Definition - It defines how the containers should run. It includes informations like Docker image, CPU and memory requirements, networking, and more.
Task - A task is an instantiation of a task definition.
Services - Helps to maintain the running of specific number of instances.
Example :
Let's say you are ECS for microservice architecture.
Clusters - Suppose your microservice based application has following services like user service, product service and order service. ECS cluster can be created to manage these services.
Task Definition - You specify the docker image, amount of CPU and memory requirements and networks configurations for your services(user service, product service and order service).
Task - It represents the running container. If you have a task definition for your user service, running a task using that task definition will start a container running the user service.
Services - you can create a service for your user service that maintains three instances of the user service task at all times. If a task fails or becomes unhealthy, ECS automatically restarts it to maintain the desired count.
Working with ECS :
Go to AWS console -> Search ECS -> Select create cluster.
Give the ECS cluster name and select infrastructure and select create.
Infrastructure - Can choose to use manual or serverless.
i) Manual - Amazon EC2 can be created and used for running container.
ii) Serverless - For serverless, AWS provides Fargate which allows to run containers without the need of managing the underlying infrastructures.
Now we need to create task definition. Select task definition option under ECS and select new task definition.
Enter the task definition family and infrastructure requirements for the container.
Enter the container details, resource allocation limits and create the task definition.
In this, I have used the container taken from Amazon ECR Public Gallery.
Task definition is created and its status is Active.
Now we need to create service. Go to Cluster -> Open the created cluster.
Edit the deployment configuration.
Create the service and you can see the status of service.
Open the service-> select the tasks
Open the task and copy the public Ip.
Paste the IP in browser and the container is up and running.
Conclusion :
In this blog, we have seen about how to deploy and manage the conatiners using AWS ECS.