Module 3 - ECS Web API

In this module we will download and deploy the ECS web API application that will hadnle the connection pooling for our Lambdas.

Create WEB API in ECS

  1. We need to clone the connection pooling web api repo:

    cd ~/
    git clone https://github.com/StevenDavid/win403-poolmanger.git
    
  2. Next we will need to update the “aws-ecs-tools-defaults.json” file. Specifically we want to update the following two fields:

    1. launch-subnets: pick two subnets with and internet gateway route
    2. launch-security-groups: we need a security group that allows for HTTP traffic on port 80 from any machine
    3. task-definition-task-role: update the {account Id} with your current account. You can get the current account ID by running the following command:

      aws sts get-caller-identity --output text --query Account
      
  3. In this step you will update the connection string in the src/webapi/Models/Helpers.cs file. Replace the {host}, {user name} and {password} with the values for your database.

    currentCSObject.host = "{host}";
    currentCSObject.username = "{user name}";
    currentCSObject.password = "{password}";
    
  4. Now we want to deploy the web API to ECS. Run the following command from the same directory as the “aws-ecs-tools-defaults.json” file:

    cd ~/win403-poolmanger/src
    dotnet ecs deploy-service
    
  5. Once the deployment is complete we need to go to ECS to get the Pool manager private IP so that we can update our lambda.

    1. Start by logging into the AWS Console.
    2. On the AWS management console home page, search for “ECS” in the “Find Services” search box. Press enter or click the “ECS” service that populates in the fast search.
    3. Click the “DotNetSQLPoolTest” cluster.
    4. On the “services” tab click the “DBTestWebapi2-service” service.
    5. Next, on the service page, click the “tasks” tab.
    6. Under the “task” column click the link (it will be a GUID string).
    7. Scroll down to the Network section and copy the “Private IP”
  6. Now we will update the lambda with the private IP

    1. Start by logging into the AWS Console.
    2. On the AWS management console home page, search for “lambda” in the “Find Services” search box. Press enter or click the “lambda” service that populates in the fast search.
    3. Click the “Functions” menu item from the left navigation.
    4. Click the function that starts with “win403-Lambda-Get”
    5. Scroll down to the “Environment variables” section and update the “baseUrl” with the IP. Note: if you want to test the url in a browser you can use the public IP from the ECS Task page.

Use Test Harness

  1. In the top left corner of the AWS console click on the Services menu.
  2. Search for ECS, and hit enter.
  3. In the ECS clusters there should be a cluster named “DotNetSQLPoolTest,” click on that cluster.
  4. There will be a service named “DBTestHarness-service.” Click on that service link.
  5. Now switch to the “Tasks” tab and click on the Task link. It will be a GUID string.
  6. Scroll down and find the public IP for your Test Harness.
  7. Copy and paste that IP in the browser to start testing!