Integrate Dynatrace Lambda Layer on 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 AWS Lambda Layer, once monitoring is enabled for the containerized Lambda function.
In a ZIP file function deployment, the Dynatrace artefacts 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.
Configuration
Copy the Lambda layer configuration snippet
Add Dynatrace AWS Lambda extension to the container image
Configuration
-
Go to Trace Python, Node.js, and Java Lambda functions and follow the Configure with environment variables instructions.
-
Open the projects
Dockerfile
in an editor and copy the environment variables from the deployment screen. Each line must be prefixed withENV
and spaces around the equal signs must be removed.1ENV AWS_LAMBDA_EXEC_WRAPPER=/opt/dynatrace2ENV DT_TENANT=abcd12343ENV DT_CLUSTER_ID=12345678904ENV DT_CONNECTION_BASE_URL=https://abcd1234.live.dynatrace.com5ENV DT_CONNECTION_AUTH_TOKEN=dt0a01...
Copy the Lambda layer configuration snippet
- On the Dynatrace Hub page, search for AWS Lambda.
- Select AWS Lambda and then select Activate AWS Lambda.
- On the Enable Monitoring for AWS Lambda Functions, copy the Lambda layer configuration snippet.
Add OneAgent extension to the container image
-
To download the contents of the Dynatrace AWS Lambda extension to the local file system, use the following code sample for dt-awslayertool or AWS CLI.
To use the following code sample, substitute
<YOUR_LAMBDA_LAYER_ARN_SNIPPET>
with the copied Lambda layer snippet.1dt-awslayertool pull <YOUR_LAMBDA_LAYER_ARN_SNIPPET> --extract DynatraceOneAgentExtensionThe following example command downloads the layer
arn:aws:lambda:us-east-1:725887861453:layer:Dynatrace_OneAgent_1_207_6_20201127-103507_nodejs:1
and extracts its contents to the local folderDynatraceOneAgentExtension
.1dt-awslayertool pull arn:aws:lambda:us-east-1:725887861453:layer:Dynatrace_OneAgent_1_207_6_20201127-103507_nodejs:1 --extract DynatraceOneAgentExtensionTo learn more about dt-awslayertool, see Github.
-
To copy the downloaded extension content into the container image and ensure that the shell script file
/opt/dynatrace
is executable, use the followingDockerfile
commands.1COPY DynatraceOneAgentExtension/ /opt/2RUN chmod +x /opt/dynatrace
Sample Dockerfile
with Dynatrace AWS Lambda extension enabled
This sample project creates a containerized Node.js Lambda function.
The project folder has the following files and folders:
1containerized-lambda-sample2├── Dockerfile3├── DynatraceOneAgentExtension4└── index.js
The content of the Dynatrace AWS Lambda Layer is assumed to be downloaded and extracted (as outlined above) to the folder DynatraceOneAgentExtension
.
The handler function is exported by the index.js
file:
1exports.handler = async () => {2 return "hello world";3}
The Dockerfile
with the modifications applied to integrate Dynatrace AWS Lambda extension to the containerized function:
1FROM public.ecr.aws/lambda/nodejs:1823COPY index.js ${LAMBDA_TASK_ROOT}45# --- Begin of enable Dynatrace OneAgent monitoring section67# environment variables copied from Dynatrace AWS Lambda deployment screen8# (prefix with ENV and remove spaces around equal signs)9ENV AWS_LAMBDA_EXEC_WRAPPER=/opt/dynatrace10ENV DT_TENANT=abcd123411ENV DT_CLUSTER_ID=123456789012ENV DT_CONNECTION_BASE_URL=https://abcd1234.live.dynatrace.com13ENV DT_CONNECTION_AUTH_TOKEN=dt0a01...1415# copy Dynatrace OneAgent extension download and extracted to local disk into container image16COPY DynatraceOneAgentExtension/ /opt/1718# make /opt/dynatrace shell script executable19RUN chmod +x /opt/dynatrace2021# --- End of enable Dynatrace OneAgent monitoring section2223CMD [ "index.handler" ]
Limitations
Monitoring via Dynatrace AWS Lambda extension on container images is supported only for images created from an AWS base image for Lambda and only for the runtimes that we support for non-containerized functions.
Additional resources
For more information on the Lambda container images, see: