Lab Guide

  1. Create a new ECS task definition for the ImageAssessor. The image source should be The ImageAssessor container needs the URL of the load balancer to send API commands to the cats containers. This is provided by creating an environment variable in the task definition with: Key: ALB_URL with value: *for example:*

  2. In the ECS Cluster create a new scheduled ECS task that runs every two minutes, and runs the ImageAssessor task. For the CloudWatch Events IAM role for this target, use the IAM role with CloudWatchEventsRole in the name.

  3. In the scheduled task, click View CloudWatch metrics. View the Invocations and TriggeredRules metrics for the CloudWatch Event to verify it has run. You may need to wait until the rule has been invoked at least once before the metrics are available in CloudWatch.

  4. Verify which cat pictures remain by querying the cats API. This will return a JSON document listing the pictures that remain in the container. Replace the URL in the example below with the URL of your load balancer: If many cats containers are running, the ImageAssessor may not have removed images from all of them. Refresh your browser to connect to a different container and list the images in that container. You may want to allow the ImageAssessor to run two or three times to remove at some images from every container before continuing. View the cats pages to confirm that some pages are now displaying a blank image.

  5. Disable the ImageAssessor schedule ECS task.

    The ImageAssessor also has the ability to restore all the cat images, just in case it was run too aggressively. It will restore the cats images if an environment variable called RESETPICTURES is set to.

  6. In the cluster, use Run new Task to run two new ImageAssessor tasks. In the Run new Task dialog, override the environment variables to add a new environment variable: Key: RESETPICTURES with value: 1

  7. These containers will run for 30 seconds and reset the pictures in the cats tasks. Verify the cat pictures have beeen restored by the cats API again. Replace the URL in the example below with the URL of your load balancer:

What’s Next

Machine Learning containers and placement constraints

Detailed Instructions

Running ECS tasks based on time and events - Detailed Instructions