Create a new ECS task definition for the ImageAssessor. The image source should be 205094881157.dkr.ecr.us-west-2.amazonaws.com/image-assessor:latest 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:
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.
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.
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.
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.
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
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: