AWS Lambda

(New in version 5.23.0)

Create a deployment package on your local machine and install the required dependencies in the deployment package. For more information, see Building an AWS Lambda deployment package for Node.js.

Add @sentry/serverless as a dependency:

Copied
$ npm install --save @sentry/serverless

You can use the AWS Lambda integration for the Node like this:

Copied
const Sentry = require("@sentry/serverless");

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
});

const yourHandler = async (event, context) => {
  // Your handler code
};

exports.handler = Sentry.AWSLambda.wrapHandler(yourHandler);

Enable Timeout Warning

Sentry reports timeout warning when the function is within 500ms of it's execution time. You can turn off timeout warnings by setting captureTimeoutWarning to false in the handler options. To change timeout warning limit, assign a numeric value (in ms) to timeoutWarningLimit

Copied
exports.handler = Sentry.AWSLambda.wrapHandler(yourHandler, {
  captureTimeoutWarning: false,
});

Behavior

With the AWS Lambda integration enabled, the Node SDK will:

  • Automatically report all exceptions from your lambda functions
  • Issue reports automatically include:
    • A link to the cloudwatch logs
    • Function details
    • sys.argv for the function
    • AWS Request ID
    • Function execution time
    • Function version
  • Sentry holds the thread for upto 2 seconds to report errors. You can change flush time limit by defining a flushTimeout value in the handler options
You can edit this page on GitHub.