AWS Lambda is one of the most, if not THE most, popular serverless computation services available today. Millions of companies and developers use it to run computations that do not need to keep state. One of the main issues with AWS Lambda is the ability to monitor the function for errors and performance. That’s where Sentry monitoring comes in. So let’s learn how about the best monitor tool for AWS Lambda – Sentry!
Intro to Sentry Monitoring Service
Sentry is a monitoring service that integrates well with many different types of applications. It has a great array of functionality and options for different monitoring needs. In this post, we set up Sentry to give more insights into your functions’ performance and errors!
There are a couple of options for how to configure Sentry to monitor AWS Lambda functions. One requires a bit more money as it deploys a CloudFormation stack to your account. This will automatically monitor any/all Lambda functions you want in that region. The other option is to add a bit of wrapper code to your Lambda function. This automatically allows your Lambda function to send monitoring events to Sentry. Both are relatively easy to configure. However, in the long run, the CloudFormation stack method will be easier to maintain if cost isn’t an issue.
Setting Up the Sentry’s AWS Lambda CloudFormation Stack
Deploying the Sentry CloudFormation Stack to your AWS account and enabling the functions you wish to have monitored is the easier method. The steps to do this can be found here (note: you must have a paid plan to choose this option).
All you need for this option is to deploy the CloudFormation stack and select the functions you wish to monitor. That’s it! You will pay a fee for whatever resources the CloudFormation stack utilizes in monitoring your Lambda functions. However, this solution is much more maintainable and easier to add monitoring to already deployed functions than the manual methods.
Setting Up Sentry’s AWS Lambda Function Wrapper
Another option for setting up Sentry to monitor AWS Lambda functions is to install Sentry packages to your project. Then configure Sentry to use your project and organization and then wrap your AWS Lambda function.
The first step is to install the Sentry Serverless package into your Lambda project. If you are using Node.js for your lambda function, run the following:
npm install --save @sentry/serverless
After the package is installed, add the following to your Lambda function before the handler method:
const Sentry = require("@sentry/serverless"); Sentry.AWSLambda.init({ dsn: "https://[email protected]/0", <<<--- Add your custom project DSN URL here // We recommend adjusting this value in production, or using tracesSampler // for finer control tracesSampleRate: 1.0, });
After you set up the configuration settings for Sentry, wrap the Lambda function with the Sentry Serverless wrapper method:
exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => { // Your handler code });
If you are using Typescript for your AWS Lambda function, you need to perform a few additional steps. Follow the steps here to get your TypeScript Lambda project setup.
Tracking Lambda Function Performance
Another option Sentry provides for AWS Lambda monitoring is monitoring runtime performance. This option gives insight into whether your functions take too long to run and hamper your user’s experience and/or increase costs; both of which are definitely unwanted. This insight can let you pinpoint what may be causing the long runtime and to resolve it ASAP. Check out the options for configuring performance monitoring here.
Conclusion
Sentry can be an excellent addition for monitoring many important aspects of your AWS Lambda functions. Make sure to like this post and leave a comment if you liked this post. Also, make sure to share it with those you believe it will also help!