Amazon ECS is a container management service for clusters. With this software, you do not need to manage clusters, as it takes care of that for you. In this short post, we will look at how to run a task in Amazon ECS Clusters.
What Is a Task in Amazon Elastic Container Service?
An instantiation of a task definition is called a task. To prepare your application to run on Amazon ECS, you must first create a task definition.
[Note: For more information, see Creating-ECS-Task-Definition (http://192.168.1.208/devops/resources/-/wikis/AWS/Creating ECS-Task-Definition).]
We can use the task definition to run a task on your ECS Cluster.
Now let’s see how to run a task on your ECS Cluster.
- AWS ECS Deployment on Console Step-by-Step
We have already created an ECS cluster based on Fargate and EC2.
[Note: For more, see Creating-an-ECS-Cluster (http://192.168.1.208/devops/resources/-/wikis/AWS/Creating-an-ECS-Cluster).]
So, let’s dive straight into how to do it!
Step 1: Go to the cluster that is created for the Task to run.
Step 2: In the cluster, select the Task Tab.

Step 3: Click on Run new Task. Here we can select the cluster on which to run your task definition and the number of copies of that Task.

Step 4: As you see in the above image, we have selected Fargate as the launch type since we have based this cluster on Fargate.
Step 5: Then, we have selected the Task definition and used the latest revision.
[Note: If you are wondering how to create a Task definition, click here Creating-ECS-Task-Definition (http://192.168.1.208/devops/resources/-/wikis/AWS/Creating-ECS-Task-Definition).]
Step 6: Select the cluster name and assign the number of Tasks to run. If you have any specific Task group, you can assign it there. You can also identify a set of related tasks as a task group. All tasks with the same task group name are considered as a set when performing spread placement.
Moving forward, another essential part of running a Task is managing its Network.

Step 7: Here in this image, we have selected the VPC for the Task.
[Note: For more, see Creating-an-Enterprise VPC (http://192.168.1.208/devops/resources/-/wikis/AWS/Creating-an-Enterprise-VPC).]
Step 8: Select your subnet and security group. If you want the Task to run on a public IP, you can enable it here or disable it here. We are allowing it here for the time being.

Step 9: Now, enable ECS managed tags if you want to and click RUN TASK. Amazon ECS automatically tags your tasks with two tags corresponding to the cluster and service names when this parameter is enabled. These tags allow you to identify tasks quickly in your AWS Cost and Usage Report.
Step 10: Now, your Task will start to provision and will be running in some moments. The provisioning time depends on how big the application is.
Step 11: Now the Task is running on your cluster!

- Create & Run Task Using AWS CLI
Use the following command on Amazon Web Services Command Line Interface to run a task on Amazon ECS clusters.
aws ecs run-task –cluster MYECScluster –task-definition UI-Only:1 –count 1 – -launch-type FARGATE –network-configuration “awsvpcConfiguration={subnets= [subnet-72f8aa3e],securityGroups=[sg-d2287ba8]}”
The output for the above command is as shown below:
{
“tasks”: [
{
“attachments”: [
{
“id”: “1a124e15-08e5-4ce7-a69b-417b3e57d622”,
“type”: “ElasticNetworkInterface”,
“status”: “PRECREATED”,
“details”: [
{
“name”: “subnetId”,
“value”: “subnet-72f8aa3e”
}
]
}
],
“availabilityZone”: “ap-south-1b”,
“clusterArn”: “arn:aws:ecs:ap-south
1:223659242865:cluster/MYECScluster”,
“containers”: [
{
{
“tasks”: [
{
“attachments”: [
{
“id”: “1a124e15-08e5-4ce7-a69b-417b3e57d622”,
“type”: “ElasticNetworkInterface”,
“status”: “PRECREATED”,
“details”: [
{
“name”: “subnetId”,
“value”: “subnet-72f8aa3e”
}
]
}
],
“availabilityZone”: “ap-south-1b”,
“clusterArn”: “arn:aws:ecs:ap-south
1:223659242865:cluster/MYECScluster”,
“containers”: [
{
“containerArn”: “arn:aws:ecs:ap-south
1:223659242865:container/MYECScluster/d050293af9e2498aab764f5206d56f50/dc2da3ff -ab71-4326-a2e4-5d504e6076c4″,
“taskArn”: “arn:aws:ecs:ap-south
1:223659242865:task/MYECScluster/d050293af9e2498aab764f5206d56f50″, “name”: “uionly”,
“image”: “223659242865.dkr.ecr.ap-south
1.amazonaws.com/365ui:latest”,
“lastStatus”: “PENDING”,
“networkInterfaces”: [],
“cpu”: “0”,
“memory”: “500”,
“memoryReservation”: “500”
}
],
“cpu”: “256”,
“createdAt”: “2021-07-01T10:23:27.390000-04:00”,
“desiredStatus”: “RUNNING”,
“enableExecuteCommand”: false,
“group”: “family:UI-Only”,
“lastStatus”: “PROVISIONING”,
“launchType”: “FARGATE”,
“memory”: “512”,
“overrides”: {
“containerOverrides”: [
{
“name”: “uionly”
}
],
“inferenceAcceleratorOverrides”: []
},
“platformVersion”: “1.4.0”,
“tags”: [],
“taskArn”: “arn:aws:ecs:ap-south
1:223659242865:task/MYECScluster/d050293af9e2498aab764f5206d56f50″, “taskDefinitionArn”: “arn:aws:ecs:ap-south-1:223659242865:task definition/UI-Only:1”,
“version”: 1,
“ephemeralStorage”: {
“sizeInGiB”: 20
}
}
],
[]
Wrapping Up
That was all about running an ECS Task. With these simplified methods, you can get your tasks up and running in no time!
At SysAlly, we experiment with Cloud and the most useful information is passed on to the world as blogs. Signup for the updates.
Until later, here’s SysAlly signing off!