On Cloudwatch Dashboard want to show ebs environment health metrics with health codes

Viewed 170

I am using cloudwatch dashboards to have and aggregated view of various services running for the application. I have number widget for the EnvironmentHealth metrics which displays the enumerated values but not the health codes as OK, WARN .. On the beanstalk monitoring option I can see the service health but want the same on dashboard. Please help.

This is what I expect

This is what I see

1 Answers

CloudWatch metrics for ElasticBeanstalk EnvironmentHealth only returns numbers. 0 is OK, 1 is info, 15 warning etc.

Not sure this is the best way but using custom widget with a lambda funcation works fine. The lambda function get the info of EB status and return it to CW dashboards.

Create Lambda function

I used python 3.9. Default setting is ok but note attach lambda IAM policy AWSElasticBeanstalkReadOnly to get EB status.

Lambda python code is below:

  • set EnvironmentName for your EB env
  • font size="56 px" color="#444444" are same as CW dashboard widget
  • Create in the same region as EB env.
import boto3


def lambda_handler(event, context):

    client = boto3.client("elasticbeanstalk")

    response = client.describe_environment_health(
        EnvironmentName="<your-env-name>", AttributeNames=["HealthStatus"]
    )

    output = (
        """<font size="56 px" color="#444444">"""
        + response["HealthStatus"]
        + """</font>"""
    )

    return output

Create Custom widget on CloudWatch dashboard

Add widget -> Custom widget -> Next -> Select the Lambda function above -> Create widget


This is my dashboard.

enter image description here

Related