Deploy as a Fargate Task

To prepare your application to run on Amazon ECS, you need a task definition. The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application. It can be thought of as a blueprint for your application. In this lab, the AWS Toolkit for Visual Studio will handle this for us.

A task is the instantiation of a task definition within a cluster. After you have created a task definition for your application within Amazon ECS, you can specify the number of tasks that will run on your cluster.

Each task that uses the Fargate launch type has its own isolation boundary and does not share the underlying kernel, CPU resources, memory resources, or elastic network interface with another task.

In this lab, we will deploy an ASP.NET Core web application to ECS as a Fargate Task.

Create new project using ASP.NET Core Web App template.

New ASP.NET Project

Name the project DojoWebApp

New ASP.NET Project

  • Select .NET Core 3.1
  • Check Enable Docker Support

New ASP.NET Project

Once project is created, you can publish it to AWS.

Right-click on the Web App Project and click Publish Container to AWS...

New ASP.NET Project

On Publish Container to AWS screen:

  • Notice Docker Repository, this is the name of the ECR repository where application’s docker image would be pushed to.
  • Under Deployment Target choose Run Task on an ECS Cluster and click Next.

New ASP.NET Project

A Task is a running container with the settings defined in the Task Definition. It can be thought of as an “instance” of a Task Definition.

Next on Launch Configuration screen:

  • Select Create an Empty Cluster and name it dojo-cluster. This will create a new cluster without any instances in it.
  • Launch Type will set to FARGATE. AWS Fargate is a serverless compute engine and removes the need to provision and manage servers.
  • Leave CPU and Memory settings as it is. This is the CPU and Memory capacity that will be allocated to your container on deployment.
  • For VPC Subnets select the default VPC and Subnet.
  • For Security Groups select Create New.
  • Select Assign Public IP Address. This will make your container application accessible over public IP.

New ASP.NET Project

Next under Task Configuration set Number of Tasks to 1 and name your Task Group. This will create a single instance of the task. Our task in this lab contains only one container, our web application.

New Task

We have the configuration setup now. In the Next step, select Create New to create new Task Definition and Container.

Task Definition

  • Leave container Port Mapping to default 80.
  • The Task Role gives the application code permissions to access other AWS services such as DynamoDB or S3 etc. In this case, it doesn’t matter because the application doesn’t access any AWS service.

Click Publish to push your application Container image to ECR, create Fargate Task Definition, and run the task.

Publish process in the Toolkit performs following steps:

  • Executes docker build to build Docker image based on the specification in Dockerfile.
  • Executes docker push to push image to Elastic Container Registry (ECR) repository.
  • Creates new task definition.
  • Creates new container definition.
  • Adds port mapping.
  • Creates CloudWatch log group.
  • Creates ECS cluster.
  • Registers new task definition revision.
  • Starts the task on new cluster.

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. Let’s start with the Container registry.

Expand Amazon Elastic Container Services >> Repositories.

Click on the dojowebapp repo to see latest image URI. This is the application published as a Docker image from the Toolkit wizard.


Next check dojo-cluster under Clusters:


  • You will see cluster Status as ACTIVE.
  • There should be one Running Fargate Task under Tasks tab.
  • Check Attachments section of the running task. Copy Public DNS or Public IP and launch it in browser.


You should see ASP.NET Core sample application up and running.


In this lab, we used the AWS Toolkit for Visual Studio wizard to create a Task Definition, an empty ECS Cluster, ECR Repository, pushed the container image and created a Task from Task definition all within Visual Studio.

If you stop this task, ECS will not re-start it automatically. This is where we can use ECS 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.