New Relic Lambda Python
This module provides a decorator, @lambda_handler that enables New Relic instrumentation of an AWS Lambda function.
New Relic recommends using its Lambda Layer for seamless instrumentation. For the manual instrumentation process, check out this guide or follow the Usage steps below.
Usage
To manually apply the lambda_handler decorator to code, see our full SDK example on our docs website, or reference the same quickstart below.
-
Download both the Python agent and Python lambda wrapper packages and place them in the same directory as your function code. To do this, use pip:
pip install -t . newrelic newrelic-lambda
-
In your Lambda code, import both the Python agent module and the Python lambda wrapper module.
-
Decorate the handler function using the New Relic decorator. The New Relic package must be imported first in your code. Here's an example:
import newrelic.agent from newrelic_lambda.lambda_handler import lambda_handler newrelic.agent.initialize() @lambda_handler() def handler(event, context): ...
-
Optional: You can also add custom events to your Lambda using the record_custom_event API. Here's an example:
@lambda_handler() def handler(event, context): newrelic.agent.record_custom_event('CustomEvent', {'foo': 'bar'}) ...
-
Zip your
lambda_function.py,newrelic/andnewrelic_lambda/folders together using these guidelines:-
The New Relic files outside the newrelic/ folder don't need to be included.
-
If your Lambda function file name is, for example, lambda_function.py, name your zip file lambda_function.zip. Do not use a tarball.
-
Your Lambda and its associated modules must all be in the zip file's root directory. This means that if you zip a folder that contains the files, it won't work.
-
-
Upload the zipped file to your AWS Lambda account.
-
To enable distributed tracing and configure environmental variables, refer environment variables documentation.
-
Invoke the Lambda at least once. This creates a CloudWatch log group, which must be present for the next step to work.
The New Relic decorator gathers data about the Lambda execution, generates a JSON message, and logs it to CloudWatch Logs. Next, configure CloudWatch to send those logs to New Relic.
Building
To build this project for local testing, use pip to create an editable install with the following command.
pip install -e .
Testing
For testing we use tox to handle generating virtual environments for each supported python version. If you have multiple Python versions available on your system, you can run the appropriate tests with the following command, using Python 3.12 as an example:
tox run -e py312
Support
New Relic hosts and moderates an online forum where you can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub. You can find this project's topic/threads here:
Add the url for the support thread here: discuss.newrelic.com
Contribute
We encourage your contributions to improve New Relic Lambda Python! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com.
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic's products or websites, we welcome and greatly appreciate you reporting it to New Relic through our bug bounty program.
If you would like to contribute to this project, review these guidelines.
License
New Relic Lambda Python is licensed under the Apache 2.0 License.
Metadata
Release files for newrelic-lambda 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| newrelic_lambda-1.0.0.tar.gz | 37.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| newrelic_lambda-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 53.1 kB
Release files / newrelic_lambda-1.0.0.tar.gz
| Download URL | newrelic_lambda-1.0.0.tar.gz |
|---|---|
| Size | 37.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
397dde5ce3905e509a41ddaa78f5df7ea9bde2e86fc65f718ba001134ade5873
|
|
BLAKE2b-256 checksum How to use checksums |
acdd27cd918d81f5b25aefc307bf55e97d9f9829cf0e35f64f9190370ce76518
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency logRelease files / newrelic_lambda-1.0.0-py3-none-any.whl
| Download URL | newrelic_lambda-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d13de0f3fec7e4082746eb6bbcaac17ac9ff906334bc987d586b5bd320836b1
|
|
BLAKE2b-256 checksum How to use checksums |
6ea10799cadb8c01a97daf73660df6d7a0ed49e8fcc82268e4126bf4be181ed7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 30, 2026.
Transparency log