Skip to main content

New Relic Open Source community project banner.

New Relic Lambda Python

GitHub release image image Tests Ruff MegaLinter codecov Secured with Trivy

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.

  1. 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
    
  2. In your Lambda code, import both the Python agent module and the Python lambda wrapper module.

  3. 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):
    ...
    
  4. 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'})
    ...
    
  5. Zip your lambda_function.py, newrelic/ and newrelic_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.

  6. Upload the zipped file to your AWS Lambda account.

  7. To enable distributed tracing and configure environmental variables, refer environment variables documentation.

  8. 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)

Source distribution for newrelic-lambda 1.0.0
File Size Uploaded
newrelic_lambda-1.0.0.tar.gz 37.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for newrelic-lambda 1.0.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page