karthik
karthik

Reputation: 499

How to create a single AWS Lambda Function to monitor the health check of multiple ALB Target groups

Can we create a single AWS Lambda function to trigger the alarm for all unhealthy targets in all Target groups in an AWS Account ?

This link https://aws.amazon.com/blogs/networking-and-content-delivery/identifying-unhealthy-targets-of-elastic-load-balancer/ provides the information to create a single lambda function to monitor and trigger an alarm for single Target Group. I need to monitor and trigger alarms for multiple target groups using one lambda function and further I need the same lambda function to trigger the SNS to send the email. Can we achieve the same ?

Upvotes: 0

Views: 2106

Answers (1)

alexis-donoghue
alexis-donoghue

Reputation: 3387

Judging from blog post contents, it is achievable while using the proposed solution as a starting point. Although you would need to change a few things.

  • You will need to associate all of the alarms with the same SNS topic. Depending on the type of alarm you trigger, you will have different data available to you in incoming SNS message. To me the most logical would be to create UnHealthyHostCount alarm on target groups themselves

  • Lambda function code suggests that function was written with having only one target group for "AWS/ApplicationELB" and "AWS/NetworkELB" alarms in mind.

  • Remove this block:

else:
    tg_arn = os.environ['TARGETGROUP_ARN'].strip()
    tg_type = (os.environ['TARGETGROUP_TYPE'].strip()).lower()
  • Extract target group ARN (tg_arn) from alarm dimension TargetGroup from the incoming SNS
  • The rest should be more or less the same

Exact steps depend on your particular setup and goals, so treat this as a rough blueprint.

Upvotes: 0

Related Questions