- Priya
- November 28, 2022
How to Create Cluster Task & Service for Elastic Container Service on Amazon Web Service(AWS).
A task is the instantiation of a task definition within a cluster. After we have created a task definition for application within Amazon ECS, we can specify the number of tasks to run on cluster.
An Amazon ECS service allows we can run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster.
Create Task
- Create a ECS cluster so click on link https://www.hackerxone.com/blog/how-create-elastic-container-service-amazon-web-serviceaws for how to create ECS.
- Click on New Created ECS cluster.
- Click on Tasks.
- Now click on Run new Task.
- Select Launch Type.
- Select existing Task definitions Family & Revision.
- Select Cluster.
- Provide Number of Tasks we want to run on cluster.
- Provide Tag key name & value.
- Click on Run Task.
- After sometime Task is running state.
Create Service
- Click on Services.
- Click on Create.
- Select Launch Type.
- Select existing Task definition Family & Revision.
- Select existing cluster.
- Provide Service name.
- Select Service type: replica or daemon. Replica scheduling strategy places and maintains the desired number of tasks across cluster.
- Daemon scheduling strategy deploys exactly one task on each active container instance that meets all of the task placement constraints that specify in cluster.
- Provide number of Tasks required.
- Set minimum & maximum healthy percent.
- We can Add load balancer.
- By default load balancer type is none.
- We can select different type of load balancer on services : application, network or classic.
- Click on Next step.
- By default Auto Scaling is disable.
- If we needs to auto scaling.
- Click on Configure Service Auto Scaling.
- Provide minimum number of Tasks.
- Provide Desired & maximum number of Tasks.
- Select Scaling policy type.
- Provide Policy name & Target value.
- Click on Next step.
- Review all configurations.
- Click on Create Service.
- New ECS Service created successfully.
- Click on View service.
- New ECS service is there with the name we provide.
Create Task & Service using Shell
- Setup aws-cli on your system so click on link https://www.hackerxone.com/blog/how-install-configure-aws-cli-ubuntu-1804
- Run the following command:
To Run a Task
aws ecs run-task –cluster <value> –task-definition <value> –count <value>
To Create a service with a Fargate task
aws ecs create-service –cluster Cluster-name –service-name Service-name –deployment-controller type=EXTERNAL –desired-count 1