This step will use CloudFormation to create the cats, dogs, and simplehomepage tasks and services within ECS, and associate the services with an Elastic Load Balancing Application Load Balancer. It will also create CloudWatch alarms for the cats and dogs services, which you will use to set up Task Auto Scaling.
-
In the AWS Console, ensure you have the correct region selected. The instructor will tell you which region to use.
-
In the Management Tools section click CloudFormation.
-
Click Create Stack.
-
Select Upload a template to Amazon S3, then click Choose File and choose the file named Lab2-create-ecs-tasks-and-services.yml
-
In Stack name, enter catsndogsECStasksandservices
-
Leave the ECSCluster and LabSetupStackName parameters at their default, unless you changed the name of the CloudFormation stack from the Lab setup, or named the ECS cluster something other than catsndogsECScluster.
-
Click Next, then click Next again, then click Create.
-
Wait until the stack status is CREATE_COMPLETE.
-
Verify the catsndogs application works by loading the website:
-
In the AWS Console, under Compute click EC2.
-
Click Load Balancers.
-
Copy the DNS Name of the load balancer with catsn-catsn in the name.
-
Paste this into a new browser tab. You should see the catsndogs.lol homepage, and should be able to click the “I love cats” and “I love dogs” links to see pages served by the cats and dogs containers, respectively.
-
In this task you will set up Task Auto Scaling for the cats and dogs services
-
In the Compute section of the AWS Console click EC2 Container Service.
-
In the ECS console click catsndogsECScluster then the service with Cats in the name.
-
Click the Update button at the top right of the console.
-
On the Configure Service page click Next Step.
-
On the Network configuration page click Next Step.
-
On the Auto Scaling page select Configure Service Auto Scaling to adjust your service’s desired count.
-
Set Minimum number of tasks to 2.
-
Set Desired number of tasks to 2.
-
Set Maximum number of tasks to 100.
-
-
In IAM role for Service Auto Scaling select the role with ECSAutoScaleRole in the name.
-
Click Add scaling policy button. Select Step scaling radio button for Scaling policy type
-
In Policy name enter CatsScaleUpPolicy.
-
In Execute policy when select Use an existing alarm and choose the alarm with CatsScaleUpAlarm in the name.
-
In Scaling action click the Add button twice.
-
Enter: Add 10 tasks when 1000 <= RequestCount < 2000
-
Enter: Add 20 tasks when 2000 <= RequestCount < 4000
-
Enter: Add 25 tasks when 4000 <= RequestCount < +infinity
-
-
Click Save.
-
Click Add scaling policy button. Select Step scaling radio button for Scaling policy type
-
In Policy name enter CatsScaleDownPolicy.
-
In Execute policy when select Use an existing alarm and choose the alarm with CatsScaleDownAlarm in the name.
-
In Scaling action click the Add button.
-
Enter: Remove 10 tasks when 1000 >= RequestCount > 100
-
Enter: Remove 5 tasks when 100 >= RequestCount > -infinity
-
-
Click Save.
-
Click Next step.
-
Click Update Service.
-
Click View Service, then click the cluster name catsndogsECScluster.
-
Click the service with Dogs in the name.
-
Click the Update button at the top right of the console.
-
On the Configure Service page click Next Step.
-
On the Network configuration page click Next Step.
-
On the Auto Scaling page select Configure Service Auto Scaling to adjust your service’s desired count.
-
Set Minimum number of tasks to 2.
-
Set Desired number of tasks to 2.
-
Set Maximum number of tasks to 100.
-
-
In IAM role for Service Auto Scaling select the role with ECSAutoScaleRole in the name.
-
Click Add scaling policy button.
-
In Policy name enter DogsScaleUpPolicy. Select Step scaling radio button for Scaling policy type
-
In Execute policy when select Use an existing alarm and choose the DogsScaleUpAlarm.
-
In Scaling action click Add twice.
-
Enter: Add 10 tasks when 1000 <= RequestCount < 2000
-
Enter: Add 20 tasks when 2000 <= RequestCount < 4000
-
Enter: Add 25 tasks when 4000 <= RequestCount < +infinity
-
-
Click Save.
-
Click Add scaling policy button.
-
In Policy name enter DogsScaleDownPolicy. Select Step scaling radio button for Scaling policy type
-
In Execute policy when select Use an existing alarm and choose the alarm with DogsScaleDownAlarm in the name.
-
In Scaling action click the Add button.
-
Enter: Remove 10 tasks when 1000 >= RequestCount > 100
-
Enter: Remove 5 tasks when 100 >= RequestCount > -infinity
-
-
Click Save.
-
Click Next step.
-
Click Update Service.
-
Click View Service, then click the cluster name catsndogsECScluster.
In this task, you will generate load to cause the cats and dogs services scale. As more cats and dogs tasks are added to the cluster, the MemoryReservation metric for the cluster will increase. Because the EC2 Spot fleet Auto Scaling is set up to scale based on MemoryReservation, this will cause the underlying EC2 Spot fleet to scale.
You will create a CloudFormation stack containing a load generator that sends load to the cats and dogs containers, and then verify the tasks scale as expected.
-
In the Management Tools section click CloudFormation.
-
Click Create Stack.
-
Select Upload a template to Amazon S3, then click Choose File and choose the file named Lab2-loadgenerator.yml.
-
In Stack name, enter catsndogslab2loadgenerator.
-
Leave the LabSetupStackName parameter at its default, unless you changed the name of the CloudFormation stack from the Lab setup.
-
Click Next, then click Next again, then click Create.
-
Wait until the stack status is CREATE_COMPLETE.
Note: the LoadGenerator instance uses the Vegeta load generator. More information about this is available at: https://github.com/tsenart/vegeta . The CloudFormation template injects the URL of your load balancer so Vegeta sends requests to the correct endpoint
-
In the AWS Console, under Management Tools click CloudWatch.
-
Click Metrics.
-
On the All metrics tab, click ApplicationELB, then Per AppELB, per AZ, per TG Metrics.
-
Find the LoadBalancer where the name starts with catsn-catsn and select the RequestCount metrics.
-
On the Graphed metrics tab, change the Statistic to Sum, and the Period to 10 seconds.
-
After a minute or two you should start to see an increase in request counts, to around 1500 each for the cats and dogs target groups. Note that the simpleHomepage target group is not accessed by the load generator.
-
Click Alarms.
-
After the load has been sustained for two minutes, the Lab2-CatsScaleUpAlarm and Lab2-DogsScaleUpAlarm should enter the ALARM state.
-
In the AWS Console, under Compute click EC2 Container Service.
-
In the ECS console click Clusters, then click the cluster catsndogsECScluster.
-
Click Services and click either the cats or dogs service.
-
Click the Events tab. You should see events as ECS adds more tasks to the Service
As more tasks are added to the cluster, the MemoryReservation metric will increase. Because the EC2 Spot fleet Auto Scaling is set up to scale based on MemoryReservation, this will cause the underlying EC2 Spot fleet to scale. In this task you will verify that Spot fleet Auto Scaling adds more EC2 instances to the cluster:
-
In the AWS Console, under Management Tools click CloudWatch.
-
Click Alarms.
-
Once sufficient copies of the cats and dogs tasks have started, the ScaleOut alarm you created in Lab 1 should change to ALARM state. Click this alarm and view the metric graph to see whether it has reached the alarm threshold.
-
Once it has reached the threshold and moved to ALARM state, move to the next step.
-
In the AWS Console, under Compute click EC2.
-
Click Spot Requests then select the Spot fleet request.
-
Click the History tab. You may see an Event Type of autoScaling with a Status of pending, otherwise you should see Event Type entries of instanceChange with a Status of launched.
-
In the AWS Console under the Compute section click EC2 Container Service.
-
In the ECS console click catsndogsECScluster.
-
Click the ECS Instances tab.
-
Verify that the new instances are added to the cluster.
In this task, you will stop the load generator. As the load stops, the number of ECS tasks and number of instances in the Spot fleet will return to their default levels.
-
In the AWS Console, under Compute click EC2.
-
Click Instances.
-
Select the instance with LoadGenerator in the name.
-
Click Actions and select Instance State, then click Stop.
Deploying a new version of the cats service with secrets management