Search code examples
javascriptnode.jsamazon-web-servicesaws-lambdaamazon-ses

Best practice for a lambda to fail / reject an event


I have an AWS Lambda that catches emails via an SNS trigger from SES.

I have a handful of validation conditions to determine if I should continue processing the event / email.

The code currently just exits from exports.handler if validation fails. However, I'd like to see validation issues in CloudWatch.

Should I throw an Error or return a particular object? I don't see much guidance in the docs for SES Notifications.

UPDATE When I say "see validation issues" in CloudWatch - I'd like to see validation issues graphed and possibly to create an alarm (lambda errors) w/ SNS topic and subscription (send email) over some threshold.


Solution

  • Your code can Publish custom metrics to Amazon CloudWatch. These metrics will appear just like any other metrics in CloudWatch Metrics.

    You can then create Alarms based on these metrics.

    This would be independent of Amazon SES Notifications.