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: README.md
+9-35
Original file line number
Diff line number
Diff line change
@@ -26,7 +26,7 @@ cd ..
26
26
27
27
```
28
28
cd nodejs
29
-
./publish-layers.sh nodejs20x
29
+
./publish-layers.sh nodejs20
30
30
cd ..
31
31
```
32
32
@@ -78,7 +78,9 @@ These steps will help you configure the layers correctly:
78
78
* Using Cloudformation, this refers to adding your layer arn to the Layers property of a [AWS::Lambda::Function resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html).
79
79
3. Update your functions handler to point to the newly attached layer in the console for your function:
80
80
* Python: `newrelic_lambda_wrapper.handler`
81
-
* Node: `newrelic-lambda-wrapper.handler`
81
+
* Node:
82
+
* CommonJS: `newrelic-lambda-wrapper.handler`
83
+
* ESM: `/opt/nodejs/node_modules/newrelic-esm-lambda-wrapper/index.handler` - You must specify the full path to the wrapper in the layer because the AWS Lambda Runtime doesn't support importing from a layer.
@@ -97,42 +99,14 @@ Refer to the [New Relic AWS Lambda Monitoring Documentation](https://docs.newrel
97
99
98
100
## Support for ES Modules (Node.js)
99
101
100
-
AWS announced support for Node 18 as a Lambda runtime in late 2022, introducing `aws-sdk` version 3 for Node 18 only. This version of `aws-sdk` patches `NODE_PATH`, so ESM-supporting functions using `import` and top-level `await` should work as expected with Lambda Layer releases `v9.8.1.1` and above (Numerical layer versions vary by region and runtime). To configure the layer to leverage `import`, add the environment variable `NEW_RELIC_USE_ESM: true`, and add this environment variable to use our ESM loader: `NODE_OPTIONS: --experimental-loader newrelic/esm-loader.mjs`.
102
+
AWS announced support for Node 18 as a Lambda runtime in late 2022, introducing `aws-sdk` version 3 for Node 18 only. This version of `aws-sdk` patches `NODE_PATH`, so ESM-supporting functions using `import` and top-level `await` should work as expected with Lambda Layer releases `v9.8.1.1` and above (Numerical layer versions vary by region and runtime). To configure the layer to leverage `import`, add this environment variable to use our ESM loader: `NODE_OPTIONS: --experimental-loader newrelic/esm-loader.mjs`. **Note**: The function handler should also use `newrelic-esm-lambda-wrapper.handler`.
101
103
102
-
Note that if you use layer-installed instrumentation with the `NEW_RELIC_USE_ESM` environment variable, your function must use promises or async/await; callback based functions are not supported. The Node wrapper uses a [dynamic import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) to attach to your function, which is an asynchronous operation. If you still need support for callback based functions, you will have to use the CommonJS based wrapper, which can be done by removing the `NEW_RELIC_USE_ESM` environment variable.
104
+
### Note on performance for ES Module functions
103
105
104
-
You may see some warnings from the Extension in CloudWatch logs referring to a non-standard handler; these warnings may be ignored.
106
+
If you are using the legacy `NEW_RELIC_USE_ESM` flag on the `newrelic-lambda-wrapper.handler`, and your ESM function depends on a large number of dependency and file imports, you may see long cold start times as a result. As a workaround, we recommend using the ESM wrapper. Set your handler to `/opt/nodejs/node_modules/newrelic-esm-lambda-wrapper/index.handler`.
105
107
106
-
If your Node functions use `import` and top-level `await` in Node 16 or Node 14 runtimes, layer-installed instrumentation will be unable to find imported modules, as [`import` specifiers don't resolve with `NODE_PATH`](https://nodejs.org/docs/latest-v16.x/api/esm.html#no-node_path). You can still instrument your functions with New Relic, but you will need to do the following:
107
-
108
-
1.[instrument your function manually](#manual-instrumentation-for-es-modules) using our [Node Agent](https://github.com/newrelic/node-newrelic/)
109
-
2. On deploying your function, don't set the function handler to our Node wrapper; instead, use your regular handler function, which you've wrapped with `newrelic.setLambdaHandler()`.
110
-
3. If you're using Node 18 or above, apply the latest Lambda Layer for your runtime. It will install both the Node agent and our Lambda Extension.
111
-
4. If you're using Node 14 or Node 16, you will have to deploy our agent with your function code, but you could use our Extension-only Lambda Layer for delivering telemetry. Use our [layer discovery website](https://layers.newrelic-external.com/) to find the ARN for your region. Look for either NewRelicLambdaExtension or NewRelicLambdaExtensionARM64 (depending on your function's architecture).
112
-
4. Add your `NEW_RELIC_LICENSE_KEY` as an environment variable.
113
-
114
-
## Note on performance for ES Module functions
115
-
116
-
In order to wrap ESM functions without a code change, our wrapper awaits the completion of a dynamic import. If your ESM function depends on a large number of dependency and file imports, you may see long cold start times as a result. As a workaround, we recommend instrumenting manually, following the instructions below.
117
-
118
-
## Manual instrumentation for ES Modules
119
-
120
-
First import the New Relic Node agent into your handler file:
121
-
122
-
```javascript
123
-
importnewrelicfrom'newrelic'
124
-
```
125
-
126
-
Then wrap your handler function using the `.setLambdaHandler` method:
### Note on legacy `NEW_RELIC_USE_ESM` environment variable
109
+
Prior to Lambda Layer releases `v12.16.0`, the wrapper for CommonJS and ESM were the same. If you wanted to wrap a ESM lambda handler you had to set `NEW_RELIC_USE_ESM` to `true`. This functionality still exists but has been deprecated. If you have a ESM lambda handler set the function handler to point to `newrelic-esm-lambda-wrapper.handler`. We will be removing `NEW_RELIC_USE_ESM` at a future date.
0 commit comments