Amazon ECS provides simple APIs to interact with your containerized application running on ECS. Using these APIs, you can launch, run, start, and stop your containerized application. Also, you can schedule the placement of the containers running the application on your desired node depending upon the resources required by the application.
Following are some terminologies used while working with the ECS cluster.
- Container and images
- Task definitions
- Task and scheduling
- Container agent
This article will learn how an ECS cluster can be created on AWS using the AWS management console.
Creating ECS cluster
First, log into the management console and go to the ECS services.
From the left side panel on the console, click on the Clusters button.
Now click on the Create cluster to start creating the cluster.
Now first, it will ask for the ECS cluster template. There are three templates available for the ECS cluster.
- Networking only
- EC2 Linux + Networking
- EC2 Windows + Networking
The Networking only template creates clusters using AWS Fargate. AWS Fargate is the latest technology provided by AWS to deploy ECS clusters. AWS Fargate is a serverless service to deploy ECS clusters, and you do not need to manage the nodes inside the cluster. Nodes are managed by AWS, and you only provide task definitions for the service. For this template, you only create the ECS cluster, and VPC and subnets are optional for this.
The EC2 Linux + Networking template creates the ECS cluster, including the Nodes running Linux AMI. In order to run an ECS cluster using the EC2 Linux + Networking template, you need to create the Cluster, VPC, subnets, and Auto scaling group with Linux AMIs. The auto-scaling group is used to manage the nodes in the cluster.
The EC2 Windows + Networking template creates the ECS cluster with Windows AMIs. You create the Cluster, subnets, VPC, and auto-scaling group with Windows AMIs. The windows instances are managed and scaled by the auto-scaling group.
AWS recommends using the AWS Fargate to run the ECS cluster, and it is the latest technology among these. So for this demo, we will use the AWS Fargate to create the ECS cluster.
After selecting the option, now click on the Next step button at the bottom right corner of the page.
It will ask for the different configurations for the ECS cluster. The name is the unique identifier for the ECS cluster, and the same name can not be used for another ECS cluster in the same region.
For cluster networking, you can create the cluster inside the VPC to isolate the ECS cluster. For this demo, we will not run the ECS cluster inside the VPC.
Cloudwatch container insights are used to monitor and troubleshoot containerized applications. It collects the different container metrics such as CPU, memory, space, and other events such as restart, stop and start to give a deep insight into the container. For this demo, we will not use the CloudWatch container insights.
After providing all the above details, click on the Next button to create the ECS cluster.
When you click on the Create button to create the ECS cluster, it will first create an IAM service-linked role for the ECS and then create the cluster.
Create ECS task definition
After creating the ECS cluster, now create an ECS task definition to deploy a sample container on the ECS cluster.
From the left side panel of the ECS console, click on the Task Definitions button.
Click on the Create new Task Definition button to create a new task definition.
First, it will ask for launch type compatibility for the task definition. There are three launch-type compatibilities for the task definitions.
The Fargate launch type compatibility is used for AWS-managed infrastructure, and there is no need to deploy any EC2 instance. This launch-type compatibility is used for ECS clusters using AWS Fargate. The cost is based on the container size.
The EC2 launch type compatibility is used for the Self-managed infrastructure on AWS, like EC2 instances having both Windows and Linux AMIs. This launch-type compatibility is used for both EC2 Linux + Networking and EC2 Windows + Networking ECS templates. The cost is based on the EC2 instances.
The External launch type compatibility is used for the ECS cluster, including Self-managed on-premises instances. The price is based on instance-hour and additional charges for other services.
For this demo, we will use the Fargate launch type compatibility as we are using the Networking only template for the ECS cluster.
After selecting the launch type compatibility, now click on the Next step button at the bottom right corner of the page. It will open a new page asking for task and container configuration.
Enter a unique name for the task definition to be created. Task role is used to make API calls to the AWS services. For this demo, leave the task role to none. Operating system family is the OS which the task definition will use. For this demo, select Linux as the operating system family.
Now scroll down to the Task execution IAM role. The Task execution IAM role must include permissions to pull the container image and publish container logs to Amazon CloudWatch. If the role does not exist, it will be created automatically by the ECS.
The task size is the memory and the number of vCPUs that will be allocated to the container for execution. For this demo, allocate 0.5 GB of RAM and 0.25 vCPU.
After allocating RAM and vCPUs, now click on the add container button to add a container. Enter the name of the container and the image that will be used by the container.
You can also specify the hard and soft limits of the resources allocated to the container. If a hard limit is specified, the container will be killed if it exceeds that limit. If a soft limit is specified, the container will reserve that amount of memory.
Port mapping is used to access container ports on the host machine. For this demo, set the port 80.
Now skip all the remaining options and click on the create button at the end of the page to create the task.
After creating the task definition, now go to the Task Definitions from the left side panel of the ECS console. Select the newly created task definition and run it using the Run task option from the Actions list.
It will ask for the different options for the container before running. Provide the Fargate as launch type as we will use Fargat as launch type compatibility.
Select Linux as the operating system of the container and provide the other details, as shown in the following image.
Select the VPC, subnet, and security groups you want to assign to the task definition.
After providing all this detail, now click on the run button to run the task definition. After running the task definition, now check the status of the task definition from the console.
Amazon ECS is a highly available and scalable service provided by AWS to run containerized applications. AWS provides different launch type compatibilities to run the containerized applications on AWS without managing the containerization tool. After creating the ECS cluster, you need to create the Task definition to run a container. This article describes how we can create and run containerized applications on AWS ECS using the AWS management console.