• EnglishEspañol日本語한국어Português
  • Log inStart now

Instrument your containerized function

If you're using a containerized image for a Lambda function and want to monitor your application, you'll need to add New Relic to your Dockerfile. For example, suppose you're a developer for a budgeting application and you're using a Lambda function to calculate account balances every time a customer clicks See my balance. You want to dive deep into any potential latencies. In that case, you'll need to add New Relic to your function, so every time a customer clicks See my balance your function runs, and New Relic does too.

Here's a diagram showing the process of adding New Relic to the Dockerfile so you can monitor your 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.

Example

Here is an example of the original Dockerfile merged with New Relic's prebuilt layer. This example uses a Node.js runtime.

# 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...

Dockerfile examples based on runtime

FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-java:17-arm64 AS layer
# Layer code
COPY --from=layer /opt/ /opt/
FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-python:38-arm64 AS layer
# Layer code
COPY --from=layer /opt/ /opt/
FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-nodejs:20-arm64 AS layer
# Layer code
COPY --from=layer /opt/ /opt/
FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-ruby:32-arm64 AS layer
# Layer code
COPY --from=layer /opt/ /opt/
FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-dotnet:arm64 AS layer
# Layer code
COPY --from=layer /opt/ /opt/
FROM public.ecr.aws/newrelic-lambda-layers-for-docker/newrelic-lambda-layers-lambdaextension:x86 as layer
# Layer code
COPY --from=layer /opt/ /opt/

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 deployment.

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.