Programming the Lambda function that calculates the cluster capacity

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 ...

Get Docker on Amazon Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.