3

I have a lambda function that copies the targets (IP addresses in this case) from one target group to another (deleting any in the second target group that don't appear in the first). This gives us 2 target groups that always match each other.

The lambda function works fine but I now need to trigger it. Is there a Cloudwatch event that is triggered when a target is registered to (or deregistered from) a target group?

theduck
  • 213
  • 2
  • 6

1 Answers1

4

Ok, after some investigation it seems like the following works:

{
  "source": [
    "aws.elasticloadbalancing"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "elasticloadbalancing.amazonaws.com"
    ],
    "eventName": [
      "RegisterTargets",
      "DeregisterTargets"
    ]
  }
}
theduck
  • 213
  • 2
  • 6
  • This will trigger the lambda on the Register and Deregister events for all the ELBs and Target Groups in that AWS account, right? Is there a way to filter the events based on the TargetGroup name or the ELB name? Or would I need to do that in the Lambda function ? – Nikhil Owalekar Jul 29 '21 at 17:29