Configuring CloudWatch events for ECS

The first task we need to perform is to set up a CloudWatch event rule, which subscribes to ECS container-instance state-change events and is configured with a target of a Lambda function that will calculate the ECS cluster capacity.

The following example demonstrates adding a CloudWatch event rule to the todobackend-aws stack.yml CloudFormation template:

......Resources:  EcsCapacityPermission:    Type: AWS::Lambda::Permission    Properties:      Action: lambda:InvokeFunction      FunctionName: !Ref EcsCapacityFunction      Principal: events.amazonaws.com      SourceArn: !Sub ${EcsCapacityEvents.Arn}  EcsCapacityEvents:    Type: AWS::Events::Rule    Properties:      Description: !Sub ${AWS::StackName} ECS Events Rule      EventPattern: source: ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.