Open the folder “SampleApp” on the desktop. Then open a solution file named “UnicornWorkshop.sln” in it.
After entering Visual Studio 2019, you will see there is a project named “InventoryService” on the right.
Right-click this project and choose “Publish Container to AWS…” After this, a wizard will show up.
For “Docker Repository”, click the drop-down list button and select the repository named unishop-repository. This repo is an Elastic Container Registry we created for you. For “Tag”, let’s type latest. Leave the default values for the other inputs and click the “Next” button.
Choose the ECS cluster named UnishopCluster, which was created for you. There are two settings you need to specify here.
5.1 For “VPC Subnets,” click the drop-down list button and tick all the subnets listed. This will allow ECS to run your tasks in multiple subnets.
5.2 For “Security Groups,” click the drop-down list button and select the security group named ECSClusterSecurityGroup. We created this security group for you. It allows connection to the Aurora database. Keep the remaining default values and click the “Next” button.
In this step, you can choose the number of instances of the service and how the instances should be deployed. You don’t need to modify any settings in this step, so please click the “Next” button.
In this step, you will define an application load balancer and its target group.
7.1 Click the white checkbox on the top left to edit the settings for the load balancer.
7.2 For “Load Balancer,” click the drop-down list button and choose “Create New.” After this, other settings will be set to default values.
7.3 For “Health Check Path”, change the default “/” to /api/unicorn. You Load Balancer will use this path to periodically send requests to its registered instances to test their status, so it must be a valid path.
7.4 Keep the remaining default values and click the “Next” button. You can read this article for more information on creating load balancers.
In this step, you will specify a task definition and publish the app to ECS.
8.1 For “Task Definition,” click the drop-down list button and choose “Create New.” After this, other settings except for “Task Role” and “Task Execution Role” will be set to default values.
8.2 Then, specify a task role. Containers running in ECS will use this role to access other AWS services. We have already created a role named ecs-task-modernization-workshop-role for the inventory service. For “Task Role”, please click the drop-down list button and choose ecs-task-modernization-workshop-role.
8.3 Next, let’s specify a task execution role. In this case, this role will be used by ECS to pull images from ECR. We have already created a role named ecs-task-execution-modernization-workshop-role. For “Task Execution Role”, please click the drop down list button and choose ecs-task-execution-modernization-workshop-role.
8.4 Keep the remaining default values and click the “Publish” button. For more infomation on configuring a task definition, please read this article.
8.5 You will see the app being published to ECS.
After the app is published to ECS, a new tab will show up Visual Studio. In this step, you will learn how to check the status of the tasks in this tab.
9.1 If you check this tab right after publishing your app, you will see one “Active” Fargate service named “InventoryService.” At the same time, you will find the “Desired tasks count” is “1,” and the “Running tasks count” is “0” because the ECS is still provisioning for your task.
9.2 Wait a minute, and then click the refresh button in the corner. You will see that the “Running tasks count” changes to “1”. Also, you can see the value for “URL” once the load balancer is running. (Provisioning the load balancer may take a little longer than launching a task.)
9.3 Please note down the value of “URL” to your cheat sheet. Since you cannot copy it directly from VS2019, you have to click the value of “URL” and copy the address from your browser. (You should paste it under “Load Balancer URL”.)
9.4 In your browser, enter the value of “Load Balancer URL” in your cheat sheet, and append /api/unicorn to the end. Then you will see info of all the unicorns returned by the inventory service.
You may have noticed that the load balancer is open to the world and does not have authentication configured. In a real-world application, you would only allow access through the API Gateway using VPC Links. For the purpose of this workshop, you can skip that configuration.
Now that the inventory service is running, let’s update the API Gateway to use it.