Deploying Asp.net core Microservices in AWS ECS using Fargate -Part II

Ravi Aakula
5 min readMar 28, 2019

--

In the previous article we learned how to deploy dotnet microservices in AWS ECS using cloudformation . In this section we will deploy the same application using AWS Console to understand each AWS service.

Step1: Application Load Balancer -ELB

  • We use ELB to distribute http requests to all ECS containers equally. ELB is fully manager load balancer in AWS
  • Once the API images are pushed to AWS ECR Repository, just verify they exist in AWS console.
  • Navigate to EC2 Service , click on Load balancers , Select “Create Load Balancer” and seelect Application Load Balancer.
  • Enter basic information an select VPC and subnets
  • Configure Securitygrooup, with required IP address to allow access ELB.
  • Enter Default Target-group name and settings. Also
  • Review and Click “Create” and navigate to the ELB Dashboard.
  • Navigate to Listeners tab and click on “View/edit rules” link .
  • Navigate to “Edit” tab and edit default rule to return fixed response 503.
  • Click on Update button and Find the DNS Name of ELB and browse.

Step 2: ECS Cluster

  • ECS is an AWS custom orchestration for containers in Cloud.
  • Navigate to “ECS” , select “Cluster” and click on “Create Cluster”.
  • Select “Network Only” option as Cluster Template. This tells ECS to use Fargate.
  • Enter name and Click Create.

Step 3: ECS TaskDefination and ECS Service

  • TaskDefination: Is set of instructions like image , environment varibles and memory size, ports to use while creating a container in this cluster.
  • Navigate to Task Definations menu under ECS and click on Create New Task defination button.
  • In the next step select Fargate as Launch type.
  • Enter name and other details like Task role- if task execution role does not exist , please create one going to IAM console.
  • Add containers to this task by clicking Add Container button at the bottom.
  • Fill the information like name, image url of this service and ports in the Container popup. You can leave the remaining settings to default, unless you have specific requirements.
  • After adding containers , just click on “Create” button and navigate to Task details page to confirm.

ECS Service is a mechanism in ECS to execute the task definitions with desired number of containers in one environment. And also you can configure the ELB target group for these containers to be available to Load balancer.

  • Navigate to Clusters dashboard and select the cluster we created.
  • Click on Create button under Services tab in the cluster detailed page.
  • Enter all basic info like lauch type, name , task defination and number of tasks.
  • Select VPC and at least two subnets(private proffered) and Security group.
  • Select the Application load balancer, that we created in Step 1.
  • Click on Add Load balancer button and and fill the information to create a separate Target group for this service. Also make sure you enter the path pattern same as your API base root path- /metadataapi* and health route.
  • Unselect Route 53 , unless you have requirement to setup route 53 DNS and click Next.
  • Review and Click Create Service.
  • Wait for few mins to run this tasks and verify the task status by going to Task tab in the Cluster Details page.
  • If you see any errors or if task never return the Running status just navigate to executing task page by clicking first link in the above page. You should be able to see details error and logs.
  • Now browse the ELB DNS name along with swagger route to verify service is running successfully.

Conclussion

Repeat the step 3 for all other services in your micro service application and they should be available on the same ELB DNS url with different routes.

http://dnsurl/metadataapi/customers

http://dnsurl/policyapi/policies

With this approach you can deploy micro services without effecting other services. Obviously this UI appoach is just to understand the various services. Mostly we should use some type of infrastructure as code technology like Cloud-formation or Terraform or AWS Code Deploy to integrate with our CI/CD tools .

References:

--

--