Centralize your AWS Lambda Errors
note: You need to deploy your Lambdas using CDK and our TypeScriptFunction construct from cdk-typescript-tooling for this to work. If you don't use it and don't want to start, no worries! We encourage you to take a peek at how we implemented it: https://github.com/xolvio/cdk-typescript-tooling/blob/master/src/typeScriptFunction.ts#L350-L356. It's pretty straightforward. Feel free to do something similar in your codebase :)
Why?
Having multiple independent lambda functions is great, but it comes with a price of difficult monitoring.
We like to be notified of things going wrong, as early as possible and in an automated fashion. New lambda functions should be connected to the system with a minimal setup.
What?
Our TypeScriptFunction has built-in ability to send Error logs to a passed lambda handler.
First, create a logHandler:
This is the simplest possible one that will just log errors in a CloudWatch stream aggregating all errors from all lambda functions.
Now in your cdk define a TypeScriptFunction that will deploy that code. Assign its handle to a variable.
Pass it to existing function like so:
Now, whenever any error (console.error or exception) shows up in the Purchase-Status-Endpoint, it will be passed and displayed by the logHandler.
Obviously, the usefulness of that increases with the number of lambdas you have. :-)
Enjoy!
https://www.npmjs.com/package/cdk-typescript-tooling?ref=xolvio.ghost.io
Let me know if you have any questions or thoughts in the comments below.