Deploy OneAgent on AWS Lambda container images

As an addition to Lambda function deployment as a ZIP file, AWS Lambda offers Lambda function deployment as container images.

The container image must include the files and configuration required to run the function code. The same applies to the files and configuration of Dynatrace OneAgent, once monitoring is enabled for the containerized Lambda function.

In a ZIP file function deployment, Dynatrace OneAgent code modules are attached to the function with an AWS Lambda extension (which is a Lambda layer with an extension-specific folder layout).

A Lambda layer, like a function bundle, is a ZIP file extracted at function cold start time to the /opt folder of the AWS Lambda function instance.

See below for how to enable Dynatrace monitoring for a containerized Lambda function.

1. Configuration

  1. Go to Deploy OneAgent as AWS Lambda extension and follow the Configure with environment variables instructions.

  2. Open the projects Dockerfile in an editor and copy the environment variables from the deployment screen. Each

line must be prefixed with ENV and spaces around the equal signs must be removed.

ENV AWS_LAMBDA_EXEC_WRAPPER=/opt/dynatrace
ENV DT_TENANT=abcd1234
ENV DT_CLUSTER_ID=1234567890
ENV DT_CONNECTION_BASE_URL=https://abcd1234.live.dynatrace.com
ENV DT_CONNECTION_AUTH_TOKEN=dt0a01...

2. Add OneAgent extension to the container image

  1. Download the contents of the Dynatrace OneAgent extension. There are two ways to do this:
    • via dt-awslayertool—this is a utility for downloading or cloning AWS Lambda layers to the local file system
    • via AWS CLI—see below for instructions

Example command:

dt-awslayertool pull arn:aws:lambda:us-east-1:725887861453:layer:Dynatrace_OneAgent_1_207_6_20201127-103507_nodejs:1 --extract DynatraceOneAgentExtension

This will download the layer arn:aws:lambda:us-east-1:725887861453:layer:Dynatrace_OneAgent_1_207_6_20201127-103507_nodejs:1 and extract its contents to the local folder DynatraceOneAgentExtension.

  1. Use the following Dockerfile commands to copy the downloaded extension content into the container image and ensure that the shell script file /opt/dynatrace is executable.
COPY DynatraceOneAgentExtension/ /opt/
RUN chmod +x /opt/dynatrace

Sample Dockerfile with Dynatrace OneAgent monitoring enabled

This sample project creates a containerized Node.js Lambda function.

The project folder has the following files and folders:

containerized-lambda-sample
├── Dockerfile
├── DynatraceOneAgentExtension
└── index.js

The content of the Dynatrace OneAgent extension is assumed to be downloaded and extracted (as outlined above) to the folder DynatraceOneAgentExtension.

The handler function is exported by the index.js file:

exports.handler = async () => {
    return "hello world";
}

The Dockerfile with the modifications applied to deploy Dynatrace OneAgent to the containerized function:

FROM public.ecr.aws/lambda/nodejs:12

COPY index.js ${LAMBDA_TASK_ROOT}

# --- Begin of enable Dynatrace OneAgent monitoring section

# environment variables copied from Dynatrace AWS Lambda deployment screen
# (prefix with ENV and remove spaces around equal signs)
ENV AWS_LAMBDA_EXEC_WRAPPER=/opt/dynatrace
ENV DT_TENANT=abcd1234
ENV DT_CLUSTER_ID=1234567890
ENV DT_CONNECTION_BASE_URL=https://abcd1234.live.dynatrace.com
ENV DT_CONNECTION_AUTH_TOKEN=dt0a01...

# copy Dynatrace OneAgent extension download and extracted to local disk into container image
COPY DynatraceOneAgentExtension/ /opt/

# make /opt/dynatrace shell script executable
RUN chmod +x /opt/dynatrace

# --- End of enable Dynatrace OneAgent monitoring section

CMD [ "index.handler" ]

Limitations

OneAgent monitoring is supported only for container images created from an AWS base image for Lambda.

Additional resources

For more information on the Lambda container images, see: