Reputation: 499
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
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()
tg_arn
) from alarm dimension TargetGroup
from the incoming SNSExact steps depend on your particular setup and goals, so treat this as a rough blueprint.
Upvotes: 0