At this point, we are calculating the appropriate metrics that determine when you need to both scale out or scale in the cluster, and the final task that needs to be performed in the function is to publish custom CloudWatch event metrics, which we can use to trigger auto scaling policies:
......Resources: ... ... EcsCapacityFunction: Type: AWS::Lambda::Function DependsOn: - EcsCapacityLogGroup Properties: Role: !Sub ${EcsCapacityRole.Arn} FunctionName: !Sub ${AWS::StackName}-ecsCapacity Description: !Sub ${AWS::StackName} ECS Capacity Manager Code: ZipFile: | import json import boto3 import datetime ecs = boto3.client('ecs') cloudwatch = boto3.client('cloudwatch') # Max memory and CPU - you would typically ...