Now that you have set up a CloudWatch event and Lambda function that is invoked whenever ECS container-instance state changes are detected, you can now implement the required application code in the Lambda function that will perform the appropriate ECS cluster-capacity calculations:
......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 ecs = boto3.client('ecs') # Max memory and CPU - you would typically inject these as environment ...