You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/organization/integrations/cloud-monitoring/aws-lambda/index.mdx
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,8 @@ description: "Learn more about Sentry's AWS Lambda integration and how you can a
6
6
7
7
<Note>
8
8
9
-
Looking for instructions to set up the serverless SDK manually? Check out these docs for [Node](/platforms/javascript/guides/aws-lambda/) or [Python](/platforms/python/integrations/aws-lambda/) instead.
9
+
This method of setting up Sentry in your Lambda functions only works if your Lambda functions are run in Node CommonJS (`require` syntax) or in Python.
10
+
For all other setups, check out these docs for [Node](/platforms/javascript/guides/aws-lambda/) or [Python](/platforms/python/integrations/aws-lambda/) instead.
description: "Configure Sentry's Lambda function wrapper"
4
+
sidebar_order: 2
5
+
---
6
+
7
+
On this page you'll learn about the options to configure the `Sentry.wrapHandler` wrapper for your Lambda function.
8
+
9
+
If you're using the AWS Lambda layer with environment variables (i.e. no Sentry code in your function), skip this guide or switch to the [initializing the SDK in code](../../install/cjs-layer#alternative-initialize-the-sdk-in-code).
10
+
11
+
## Flush Timeout
12
+
13
+
Sentry keeps the lambda function thread alive for up to 2 seconds to ensure reported errors are sent. You can change this flush time limit by defining a `flushTimeout` value in the handler options:
14
+
15
+
```javascript {filename:index.js} {2}
16
+
exports.handler=Sentry.wrapHandler(yourHandler, {
17
+
flushTimeout:1000,
18
+
});
19
+
```
20
+
21
+
## Timeout Warning
22
+
23
+
Sentry reports timeout warnings when the Lambda function is within 500ms of its execution time. You can turn off timeout warnings by setting `captureTimeoutWarning` to `false` in the handler options.
24
+
25
+
```javascript {filename:index.js} {2}
26
+
exports.handler=Sentry.wrapHandler(yourHandler, {
27
+
captureTimeoutWarning:false,
28
+
});
29
+
```
30
+
31
+
To change the timeout warning limit, assign a numeric value (in ms) to `timeoutWarningLimit`:
32
+
33
+
```javascript {filename:index.js} {2}
34
+
exports.handler=Sentry.wrapHandler(yourHandler, {
35
+
timeoutWarningLimit:700,
36
+
});
37
+
```
38
+
39
+
## Capture Rejected Promises in `Promise.allSettled`
40
+
41
+
By default, Sentry captures errors raised by your handler.
42
+
However, your handler might return a `Promise.allSettled` result.
43
+
In this case, even if one of the messages has failed, Sentry won't capture any exception.
44
+
45
+
The `captureAllSettledReasons` (default: `false`) option captures all promise rejected results
@@ -13,115 +13,33 @@ Looking for instructions on how to add Sentry without modifying your code? [Chec
13
13
14
14
</Note>
15
15
16
-
Before you begin, note:
16
+
On this page you'll get an overview how to install, configure and use Sentry in your AWS Lambda functions. Once set up, our SDK will automatically report error and performance data from your Lambda Functions. Issues in Sentry will automatically include cloudwatch data, function details and execution time measurements.
17
17
18
-
- The estimated time to configure the integration is 5 - 15 minutes.
19
-
- You need to have experience with AWS console and a basic understanding of Lambda.
20
-
- You'll need an AWS account and you have to create an [IAM user](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users_create.html).
18
+
## Installation
21
19
22
-
<Note>This guide is for version 8.0.0 and up of `@sentry/aws-serverless`.</Note>
20
+
Depending on your setup, there are different ways to install and use Sentry in your Lambda functions. We recommend one of the following options:
23
21
24
-
## Install
22
+
-[Install the Sentry AWS Lambda Layer](./install/cjs-layer) if your Lambda functions are written in CommonJS (CJS) using `require` syntax.
23
+
-[Install the Sentry AWS NPM package](./install/esm-npm) if your Lambda functions are running in EcmaScript Modules (ESM) using `import` syntax.
If you're not sure which installation method to use or want an overview of all available options to use Sentry in your Lambda functions, read the [installation methods overview](/guides/aws-lambda/install).
29
26
30
-
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](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-deployment-package-nodejs/).
After installing the SDK, you might want to configure some parameters. Besides the [common SDK configuration](./configuration/), you can also [configure Sentry's Lambda Function handler wrapper](./configuration/lambda-wrapper) to optimize function runtime overhead and timeout warnings.
33
30
34
-
We also support [installing Sentry in Lambda Layer](/platforms/javascript/guides/aws-lambda/layer/).
31
+
## Verify
35
32
36
-
## Configure
33
+
Once set up, verify that Sentry is reporting errors correctly by throwing a sample error in one of your functions:
37
34
38
-
You can use the AWS Lambda integration for the Node like this:
39
-
40
-
<SignInNote />
41
-
42
-
```javascript {tabTitle:async}
43
-
constSentry=require("@sentry/aws-serverless");
44
-
45
-
Sentry.init({
46
-
dsn:"___PUBLIC_DSN___",
47
-
48
-
// Add Tracing by setting tracesSampleRate and adding integration
49
-
// Set tracesSampleRate to 1.0 to capture 100% of transactions
50
-
// We recommend adjusting this value in production
Sentry reports timeout warning when the function is within 500ms of its 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`
80
-
81
-
```javascript {tabTitle:captureTimeoutWarning}
82
-
exports.handler=Sentry.wrapHandler(yourHandler, {
83
-
captureTimeoutWarning:false,
84
-
});
85
-
```
86
-
87
-
```javascript {tabTitle:timeoutWarning}
88
-
exports.handler=Sentry.wrapHandler(yourHandler, {
89
-
timeoutWarningLimit:50,
90
-
});
91
-
```
92
-
93
-
## Capture Rejected Promises in `Promise.allSettled`
94
-
95
-
By default, Sentry captures errors raised by your handler.
96
-
However, your handler might return a `Promise.allSettled` result.
97
-
In this case, even if one of the messages has failed, Sentry won't capture any exception.
98
-
99
-
The `captureAllSettledReasons` (default: `false`) option captures all promise rejected results
100
-
101
-
```javascript {tabTitle:captureAllSettledReasons}
102
-
exports.handler=Sentry.wrapHandler(
103
-
() => {
104
-
returnPromise.allSettled([
105
-
Promise.rejected(newError("first")),
106
-
Promise.rejected(newError("second")),
107
-
]);
108
-
},
109
-
{ captureAllSettledReasons:true }
110
-
);
111
-
// `first` and `second` errors are captured
112
-
```
113
-
114
-
## Behavior
115
-
116
-
With the AWS Lambda integration enabled, the Node SDK will:
117
-
118
-
- Automatically report all events from your Lambda Functions.
119
-
- Allows you to <PlatformLinkto="/configuration/sampling/#configuring-the-transaction-sample-rate">modify the transaction sample rate</PlatformLink> using <PlatformIdentifiername="traces-sample-rate" />.
120
-
- Issue reports automatically include:
121
-
- A link to the cloudwatch logs
122
-
- Function details
123
-
- sys.argv for the function
124
-
- AWS Request ID
125
-
- Function execution time
126
-
- Function version
127
-
- Sentry holds the thread for up to 2 seconds to report errors. You can change flush time limit by defining a `flushTimeout` value in the handler options
description: "Learn how to add the Sentry Node Lambda Layer to use Sentry in your Lambda functions running in CommonJS (CJS)"
4
+
sidebar_order: 1
5
+
---
6
+
7
+
The easiest way to get started with Sentry is to use the Sentry [Lambda Layer](https://docs.aws.amazon.com/Lambda/latest/dg/configuration-layers.html) instead of adding `@sentry/aws-serverless` with `npm` or `yarn`[manually](../cjs-manual).
8
+
If you follow this guide, you don't have to worry about deploying Sentry dependencies alongside your function code.
9
+
To actually start the SDK, you can decide between setting up the SDK using environment variables or in your Lambda function code. We recommend using environment variables as it's the easiest way to get started. [Initializing the SDK in code](#alternative-initialize-the-sdk-in-code) instead of setting environment variables gives you more control over the SDK setup if you need it.
10
+
11
+
<Note>
12
+
13
+
This installation method **does not** work with Lambda functions running in EcmaScript Modules (ESM) mode, using `import` syntax. If you're running your function in ESM, follow the [ESM guide](../esm-npm).
14
+
15
+
</Note>
16
+
17
+
## 1. Prerequisites
18
+
19
+
Before you begin, make sure you have the following:
20
+
21
+
- You have a Lambda function that is running in CommonJS (CJS) mode, using `require` syntax.
22
+
- You know the AWS region that your function is deployed to.
23
+
24
+
## 2. Add the Sentry Lambda Layer
25
+
26
+
Add the Sentry Layer by navigating to your Lambda function. Select **Layers**, then **Add a Layer**.
27
+
28
+

29
+
30
+
**Specify an ARN** tab as illustrated:
31
+
32
+

33
+
34
+
Finally, set the region and copy the provided ARN value into the input.
35
+
36
+
<LambdaLayerDetailcanonical="aws-layer:node" />
37
+
38
+
<br />
39
+
40
+
## 3. Initialize the SDK with Environment Variables
41
+
42
+
The easiest way to set up the SDK is to start and configure it using environment variables. This way, you don't have to modify your Lambda function code.
To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**:
55
+
56
+

57
+
58
+
## Alternative: Initialize the SDK in Code
59
+
60
+
Instead of [Step 3, setting environment variables](#3-initialize-the-sdk-with-environment-variables), you can also manually initialize the SDK in your Lambda function code.
61
+
This way, you can customize the SDK setup further.
62
+
Note that you don't have to actually install an NPM package for this to work, as the package is already included in the Lambda Layer.
63
+
64
+
Make sure you completed [step 1](#1-prerequisites) and [step 2](#2-add-the-sentry-lambda-layer) before proceeding.
It's important to add both, the `Sentry.init` call outside the handler function and the `Sentry.wrapHandler` wrapper around your function to automatically catch errors and performance data.
83
+
84
+
That's it - you're all set!
85
+
86
+
## Lambda layer for v7 SDK
87
+
88
+
The instructions above are written for SDK version 8 (the most recent version).
89
+
You can also install a v7 version of the Sentry Lambda layer in case you can't upgrade to v8.
90
+
The procedure is identical to the instructions above except for two differences:
Modify and copy the ARN value for your region into the input, e.g. for region `:us-west-1` and the current v7 Lambda layer version `:3`:
101
+
102
+
### v7 package name
103
+
104
+
The `@sentry/aws-serverless` package was called `@sentry/serverless` prior to version 8. Therefore, for the v7 layer, adjust your `NODE_OPTIONS` environment variable:
0 commit comments