ECS Service

What is an ECS Service?

Amazon ECS allows you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. This is called a service. If any of your tasks should fail or stop for any reason, the Amazon ECS service scheduler launches another instance of your task definition to replace it and maintain the desired count of tasks in the service depending on the scheduling strategy used.

In addition to maintaining the desired count of tasks in your service, you can optionally run your service behind a load balancer. The load balancer distributes traffic across the tasks that are associated with the service.

Click here to learn more about ECS Services.

Creating a service in the ECS

Click on Task Definitions menu, select awsbuilders-task-definition and then select awsbuilders-task-definition:1.

Click on Actions and then select Create Service.

Select the options below:

  1. Launch type: Fargate
  2. Cluster: awsbuilders-cluster
  3. Service Name: awsbuilders-task-service

Also, insert the number 1 for Number of tasks.

Select Rolling update and click on Next Step.

Click here to learn more about Blue/Green deployment and ECS.

Select your default VPC and at least two subnets.

These are the subnets where your containers will be running.

This is for testing purposes only. In a production environment, you must use multilayered design to avoid exposing your containers.

Keep scrolling down - select Application Load balancer and click on EC2 Console to create a new load balancer.

Let’s create an Application load balancer to be in front of your application.

Type awsbuilders-alb for the name and select internet facing.

Also, select your default vpc and at least two subnets.

Click on Next: Configure Security groups.

Select Create a new security group and then click on Next: Configure Routing.

Create a new target group using the name awsbuilders-alb-targetgroup, select IP as a Target Type and then click on Next: Register targets.

Don’t add any target now and click on Next: Review.

Review the settings and click on Create to deploy your Application Load Balancer.

Return to the ECS Service tab and refresh the load balancer list.

You should be able to select the newly created ALB.

Click on Add to load balancer.

Now, you select the target group name awsbuilders-alb-targetgroup.

Move to the next step by clicking on Next Step.

Finally, hit the button Create Service.

Check if all steps are green and click on View Service to open the new ECS Service.