• /
  • EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

Containerized instrumentation

If you're using a containerized image for a Lambda function and want to monitor your application, you'll need to add a pre-built New Relic Lambda layer to your Dockerfile that matches your function's runtime.

Here's a diagram showing the process of adding New Relic to the Dockerfile so you can monitor your function:

A diagram demonstrating how New Relic integrates with your Lambda containerized function.

If you're using a containerized image for your Lambda function you can add New Relic to your image.

Here's a guide to adding our pre-built layer to your code.

Add New Relic to your Dockerfile

New Relic offers pre-built images that include our layer's different runtimes: Java, Node.js, Python, and extension-only.

  1. Select the layer compatible with your specific Lambda function's runtime and region:

  2. In your multi-stage Dockerfile, use New Relic's prebuilt image as an intermediate build stage. Then, copy New Relic's agent and extension from our prebuilt image into your final build stage.

    Dockerfile examples based on runtime

    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-java:21 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/java:21
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to one of New Relic's handler wrappers
    CMD [ "com.newrelic.java.HandlerWrapper::handleRequest" ]
    # CMD [ "com.newrelic.java.HandlerWrapper::handleStreamsRequest" ]

    Try out working example of a Java containerized Lambda function using SAM.

    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-python:311 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/python:3.11
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic_lambda_wrapper.handler" ]

    Try out working example of a Python containerized Lambda function using SAM.

    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-nodejs:20 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/nodejs:20
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic-lambda-wrapper.handler" ]

    Try out working example of a Node.js containerized Lambda function using SAM.

    # Define the New Relic pre-built image
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-ruby:33 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/ruby:3.3
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override to New Relic's handler wrapper
    CMD [ "newrelic_lambda_wrapper.handler" ]
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-dotnet:x86_64 AS layer
    # Define the base image
    FROM public.ecr.aws/lambda/dotnet:8
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override not needed since the dotnet layer does not have a handler wrapper
    FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-lambdaextension:x86 as layer
    # Any lambda base image can be used
    # Copy New Relic Layer code
    COPY --from=layer /opt/ /opt/
    # Rest of your Dockerfile...
    # CMD override not needed since the extension layer does not have an agent

Create an image

  1. After you add the reference to New Relic's pre-built image to your Dockerfile, you'll need to build a new image from the modified Dockerfile. This new image will have your original code and New Relic's pre-built image. To do this, we recommend following the steps listed in the AWS guide, Create a Lambda function using a container image.
  2. Push the new image to your AWS Elastic Container Registry repository for your function to use.

Create a new Lambda function

Using the image you pushed to AWS ECR, create a new Lambda function. For more information on creating this function, we recommend going back to the AWS guide: Create a Lambda function.

Configure your Lambda function

  1. Configure the Lambda function with the same settings as your original function, but ensure you add any required environment variables for New Relic Lambda monitoring. See our Environment variables for more information.
  2. Update your function's handler to point to the newly attached layer in cmd override for your function. You can do that using the instructions in these two docs:
Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.