Skip to content

Commit 06f183a

Browse files
committed
feat(aws-lambda): Use versioned docs for v7 and v8 lambda layers
1 parent 60a400f commit 06f183a

File tree

3 files changed

+191
-26
lines changed

3 files changed

+191
-26
lines changed

docs/platforms/javascript/guides/aws-lambda/install/cjs-layer.mdx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -88,29 +88,3 @@ exports.handler = Sentry.wrapHandler(async (event, context) => {
8888
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.
8989

9090
That's it - you're all set!
91-
92-
## Lambda layer for v7 SDK
93-
94-
The instructions above are written for SDK version 8 (the most recent version).
95-
You can also install a v7 version of the Sentry Lambda layer in case you can't upgrade to v8.
96-
The procedure is identical to the instructions above except for two differences:
97-
98-
### v7 layer ARN
99-
100-
The v7 Lambda layer has a different ARN:
101-
102-
```
103-
arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv7:3
104-
```
105-
106-
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`:
107-
108-
### v7 package name
109-
110-
The `@sentry/aws-serverless` package was called `@sentry/serverless` prior to version 8. Therefore, for the v7 layer, adjust your `NODE_OPTIONS` environment variable:
111-
112-
```bash
113-
NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto"
114-
```
115-
116-
The other environment variables remain the same as above.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Lambda Layer - CJS
3+
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/serverless` with `npm` or `yarn` manually.
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+
<Alert>
12+
13+
This installation method **does not** work with Lambda functions running in EcmaScript Modules (ESM) mode, using `import` syntax.
14+
15+
</Alert>
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+
![](./img/lambda_view.png)
29+
30+
**Specify an ARN** tab as illustrated:
31+
32+
![](./img/add_layer.png)
33+
34+
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 `10`:
35+
36+
```
37+
arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv7:10
38+
```
39+
40+
<br />
41+
42+
## 3. Initialize the SDK with Environment Variables
43+
44+
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.
45+
46+
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).
47+
48+
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
49+
50+
<OnboardingOptionButtons options={["error-monitoring", "performance"]} />
51+
52+
Set the following environment variables in your Lambda function configuration:
53+
54+
```bash {"onboardingOptions": {"performance": "3"}}
55+
NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto"
56+
SENTRY_DSN="___PUBLIC_DSN___"
57+
SENTRY_TRACES_SAMPLE_RATE="1.0"
58+
```
59+
60+
To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**.
61+
62+
## Alternative: Initialize the SDK in Code
63+
64+
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.
65+
This way, you can customize the SDK setup further.
66+
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.
67+
68+
Make sure you completed [step 1](#1-prerequisites) and [step 2](#2-add-the-sentry-lambda-layer) before proceeding.
69+
70+
```javascript {filename:index.js} {"onboardingOptions": {"performance": "5-8"}}
71+
const Sentry = require("@sentry/serverless");
72+
73+
Sentry.init({
74+
dsn: "___PUBLIC_DSN___",
75+
// Add Tracing by setting tracesSampleRate and adding integration
76+
// Set tracesSampleRate to 1.0 to capture 100% of transactions
77+
// We recommend adjusting this value in production
78+
// Learn more at
79+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
80+
tracesSampleRate: 1.0,
81+
});
82+
83+
exports.handler = Sentry.wrapHandler(async (event, context) => {
84+
// Your handler code
85+
});
86+
```
87+
88+
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.
89+
90+
That's it - you're all set!
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
title: Lambda Layer - CJS
3+
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-npm).
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+
<Alert>
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+
</Alert>
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+
![](./img/lambda_view.png)
29+
30+
**Specify an ARN** tab as illustrated:
31+
32+
![](./img/add_layer.png)
33+
34+
Modify and copy the ARN value for your region into the input, e.g. for region `us-west-1` and the current v8 Lambda layer version `7`:
35+
36+
```
37+
arn:aws:Lambda:us-west-1:943013980633:layer:SentryNodeServerlessSDKv8:7
38+
```
39+
40+
<Alert>
41+
42+
Previously, the v8 Lambda layer was published under the `SentryNodeServerlessSDK` name.
43+
This target will not receive updates anymore.
44+
45+
If you need to continue using v8 please use the `SentryNodeServerlessSDKv8` layer as described above.
46+
47+
</Alert>
48+
49+
<br />
50+
51+
## 3. Initialize the SDK with Environment Variables
52+
53+
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.
54+
55+
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).
56+
57+
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
58+
59+
<OnboardingOptionButtons options={["error-monitoring", "performance"]} />
60+
61+
Set the following environment variables in your Lambda function configuration:
62+
63+
```bash {"onboardingOptions": {"performance": "3"}}
64+
NODE_OPTIONS="-r @sentry/aws-serverless/awslambda-auto"
65+
SENTRY_DSN="___PUBLIC_DSN___"
66+
SENTRY_TRACES_SAMPLE_RATE="1.0"
67+
```
68+
69+
To set environment variables, navigate to your Lambda function, select **Configuration**, then **Environment variables**:
70+
71+
![](./img/cjs_env_vars.png)
72+
73+
## Alternative: Initialize the SDK in Code
74+
75+
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.
76+
This way, you can customize the SDK setup further.
77+
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.
78+
79+
Make sure you completed [step 1](#1-prerequisites) and [step 2](#2-add-the-sentry-lambda-layer) before proceeding.
80+
81+
```javascript {filename:index.js} {"onboardingOptions": {"performance": "5-8"}}
82+
const Sentry = require("@sentry/aws-serverless");
83+
84+
Sentry.init({
85+
dsn: "___PUBLIC_DSN___",
86+
// Add Tracing by setting tracesSampleRate and adding integration
87+
// Set tracesSampleRate to 1.0 to capture 100% of transactions
88+
// We recommend adjusting this value in production
89+
// Learn more at
90+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
91+
tracesSampleRate: 1.0,
92+
});
93+
94+
exports.handler = Sentry.wrapHandler(async (event, context) => {
95+
// Your handler code
96+
});
97+
```
98+
99+
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.
100+
101+
That's it - you're all set!

0 commit comments

Comments
 (0)