Getting Started with AWS
Deploy a .NET Web Application on Amazon ECS powered by Graviton2
Module 5: Deploy the Application to Amazon ECS
In this module, you will launch new Tasks under Amazon ECS Service
So far in the guide you have prepared the foundational environment for your sample application in Module 1 and Module 2. In Module 3 you built and published the Docker image for the sample application, and in Module 4 you created the building blocks required to launch a Load Balanced Amazon ECS Service that will instantiate tasks behind the AWS Application Load Balancer.
What You Will Learn
- You’ll learn how to launch new Tasks under Amazon ECS Service.
Amazon 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. For more information on services, see Amazon ECS services.
Time to Complete
Create ECS Service
1. Select the Cluster - Graviton2ECSCluster.
2. Under the Services Tab, click Deploy button.
3. Under the Environment Section, expand Compute Configuration (advanced) section.
4. Select the Cluster you created (should already be selected) i.e. Graviton2ECS.
5. Select Launch Type as EC2 from the dropdown.
6. Under Deployment configuration section select Service, and under Task definition - Family select the task you created - Graviton2ECSTask, and Revision as LATEST.
7. Enter name as Graviton2ECSService.
8. Enter value for Desired Tasks to be 2, as shown in the screenshot below:
Stay on the same screen, you’ll set up Load Balancing for the Service.
Set up Load Balancing
1. Expand Load balancing - optional section, select Create a new load balancer and enter name as Graviton2ECSALB.
2. Ensure Listener Port is 80 and Protocol HTTP.
3. Enter Target group name as Graviton2ECS-ALB-TG and protocol as HTTP.
Define Networking boundaries
1. In the Networking section, select TargetVPC under the VPC dropdown.
2. Select public subnets - TargetVPC-public-a and TargetVPC-public-b, under the Subnets dropdown, this is only required for ALB configuration. You should be able to find the subnet IDs for the these subnets in Subnets list view by searching for their names.
3. Under Security group select - Use an existing security group and choose <CloudFormation-Stack-Name>-ALBSG security group. If you used the name suggested in Module 1, it should start with ContainerizeDotNetOnECSGraviton2-ALBSG.
4. Leave rest of the settings to default.
5. Click Deploy button. Service deployment can take a few minutes. Once finished the Cluster will look like below:
6. Click on Service Graviton2ECSService from the list of Services to view the Tasks running, Health check status and notifications.
You can note the Desired and Running count to verify that ECS Service has successfully instantiated desired number of tasks. At this stage, your Sample Application is live, under a single Task, behind an Application Load Balancer.
Enable Session Management for Sample Application
Sample .NET web application has Login Functionality, which enables logged-in user to edit the records, stored in Aurora DB.
For the session management, this guide takes the simplest route by enabling sticky session, instead of adding complexity in the .NET sample app.
Sticky sessions are a mechanism to route requests from the same client to the same target. Elastic Load Balancers support sticky sessions. Stickiness is defined at a target group level.
So the next step is to modify the Load balancing target group created by the ECS Service - Graviton2ECS-ALB-TG, and enable Session stickiness.
1. Go to EC2 from the Services drop down in the top navigation or search for EC2, click on Target Groups from Load Balancing category in the left hand side navigation pane.
2. Choose the name of Graviton2ECS-ALB-TG target group to open its details page.
3. On the Group details tab, in the Attributes section, choose Edit.
On the Edit attributes page,
4. Select Stickiness.
5. For Stickiness type, select Load balancer generated cookie.
6. For Stickiness duration, leave the default value of 1 day.
7. Choose Save changes.
Test the deployment
Now the application is ready for testing, and you need to find the public facing URL of the application, which is the DNS Name of the Application Load Balancer created by ECS Service.
1. Staying on EC2 Service console, click on Load Balancers on the left side Navigation pane, and select Graviton2ECSALB.
2. Copy the value of DNS Name as shown below:
3. Open the copied URL in a new Browser window, It should open the Sample application.
Application is in read-only for anonymous users, to be able to modify the data, you can login to the application using following admin credentials:
- Username: admin
- Password: Pass@word1
When you logged in for the first time, application asks you to set a new password for your user, choose a new password and continue.
This step completes the deployment of Sample .NET Web Application on Amazon ECS.
Here is what your architecture looks like right now:
You have now successfully containerised and deployed a .NET application on Graviton2 instance via Amazon Elastic Container Service.