1

I would like to be able to see in Cloudwatch metrics (and Lambda metrics) errors for handle exception.

For the moment I see the errors only in Cloudwatch log group for handled errors.

Here is the code I use in my Lambda

def lambda_handler(event, context):
    try:
       raise Exception("My exeception")
    except Exception as e:
       logger.exception(str(e))
       continue

And my logger is defined like this

import logging

logger =  logging.getLogger()
logger.setLevel(logging.INFO)

With this configuration I can just see errors in my logs group, but not in the lamda/cloudwatch metrics

enter image description here

Nico
  • 103
  • 1
  • 11

1 Answers1

1

According to your given code snippet, the lambda execution was completed successfully. To track the failure and success you've to just raise the exception in case of failure and handle it in case of success.

def lambda_handler(event, context):
    # try:
    raise Exception("My exception")
    # except Exception as e:
    # logger.exception(str(e))
    # continue
The logger will show all the logged error/success messages in the stream.

So, if you'll handle the error, then it won't be a failure execution hence no failure on the graph.

  • I would like to be able to see errors even for handled exceptions. What I am looking for, is to manually (with `boto3`) be able to trigger an error to see it in cloudwatch lambda metrics. Something similar to [this](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/example_cloudwatch_Usage_MetricsAlarms_section.html), but instead of sending an email, trigger an error to be visible in the cloudwatch lambda metrics. – Nico Feb 12 '22 at 13:18