Deploy as a Fargate Service

An Amazon ECS service enables you to run and maintain a specified number of instances of a task definition simultaneously in an Amazon ECS cluster. 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 in order to maintain the desired number of tasks in the service.

Go to your Visual Studio web application project -> right click on the project in Solutions Explorer and click Publish Container to AWS...

Publish

Select Deployment Target as Service on an ECS Cluster leaving everything else as it is and click Next.

Container as Service

Next on the Launch Configuration screen:

  • Select dojo-cluster. This cluster was created the previous module.
  • Use the security group created by the toolkit in the previous module. Click on Security Groups drop-down to select it.

Launch Config

Next on the Service Configuration screen:

  • We want to Create New service. Name it dojo-service.
  • We want this Service to launch and manage two tasks. Select 2 for Number of Tasks.
  • We want minimum two tasks running all the time hence we will have Minimum Healthy Percent to 100 percent.
  • Click Next button to go to the next page.

Service Config

We are not configuring Application Load Balancer Configuration in this lab, you can skip this screen by clicking Next button.

Next on the Task Definition screen we want to create a newer revision of our existing task and container hence we will select our existing Task Definitionas dojo-Task and Container as DojoWebApp container.

Service Config

With other settings as default, click Publish button.

Please note that deployment process will take few minutes.

Verify deployment

You can now review the objects created by the AWS Toolkit for Visual Studio wizard.

In AWS Explorer, click Clusters, then open dojo-cluster and go to Services tab. You will see the service deployed by the wizard.

  • Desired tasks should be 2.
  • Running tasks should be 2.

Service

Go to Tasks Tab. You should see one Task from previous deployment and two new Tasks with Task Group named service:dojo-service. These two tasks are managed by service that wizard deployed.

Task List

If you notice, this is no different from ECS Task you created in previous module. So, what is the advantage of launching your task as a service?

Click on Stop All button.

Task List

After few seconds, you would see 2 tasks launched automatically by ECS Service to meet desired count of 2 (100%) as we mentioned in task definition. Also please note that ECS Task from the previous module is not re-launched.

Task List

After few seconds both tasks will be up and running again:

Task List

So you can copy Public IP and open it in a browser to verify that application is up and running as before:

Service run

Conclusion

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 in order to maintain the desired number of tasks in the service. For applications that you want to run continuously, like web applications, using an ECS service is ideal.