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.
Name the project
.NET Core 3.1
Enable Docker Support
Once project is created, you can publish it to AWS.
Right-click on the Web App Project and click
Publish Container to AWS...
On Publish Container to AWS screen:
Docker Repository, this is the name of the ECR repository where application’s docker image would be pushed to.
Run Task on an ECS Clusterand click
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:
Create an Empty Clusterand name it
dojo-cluster. This will create a new cluster without any instances in it.
Launch Typewill set to
FARGATE. AWS Fargate is a serverless compute engine and removes the need to provision and manage servers.
Memorysettings as it is. This is the CPU and Memory capacity that will be allocated to your container on deployment.
VPC Subnetsselect the default VPC and Subnet.
Assign Public IP Address. This will make your container application accessible over public IP.
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.
We have the configuration setup now. In the Next step, select
Create New to create new
Task Definition and
Port Mappingto default
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:
docker buildto build Docker image based on the specification in
docker pushto push image to Elastic Container Registry (ECR) repository.
Please note that deployment process will take few minutes.
You can now review the objects created by the AWS Toolkit for Visual Studio wizard. Let’s start with the Container registry.
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.
Running Fargate Taskunder
Attachmentssection of the running task. Copy
Public IPand 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
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.