Installing the Datadog Lambda Extension - Layers and Environment Variables
What you add to a Lambda function is two layers, the Extension itself and the library for your runtime, the ARN of an API key stored in Secrets Manager, and environment variables for the destination and the three reserved tags. This article follows the procedure step by step, through pinning versions, choosing the tool to install with, and duplicate log collection when moving from the Forwarder.
The Extension is a lightweight version of the Agent that runs next to the function
What the Datadog Lambda Extension carries, over which path, and how it divides the work with the Forwarder is left to the explanation of Serverless Monitoring; here we follow the procedure for adding it to a function step by step. Once it is installed, you no longer need to set up a CloudWatch Logs subscription filter for each function, and the wiring is contained within the function's configuration (as of October 2026; source: Deciding to migrate to the Datadog Lambda extension). What you add to the function is three things: two layers, a way to pass the API key, and environment variables for the destination and tags. The examples are shown in Python, but the Extension's layer name does not include a runtime, and you add the same one to functions in any language.
Two layers, or bundled in the Dockerfile for container images
For functions distributed as zip files, add two layers. One is the Extension itself, whose ARN takes the form arn:aws:lambda:<AWS_REGION>:464622532012:layer:Datadog-Extension:<VERSION>. The other is the Datadog Lambda library for the runtime, named Datadog-<RUNTIME> with a version appended in the same way. For arm64 functions, both use separate layers whose names end with -ARM, and in AWS GovCloud the publisher's account ID also changes (as of October 2026; source: Instrumenting Python Serverless Applications). The Extension is a compiled binary that comes in two variants, x86 and arm64, so choose the one that matches the function's architecture.
| Distribution method | Extension | Library | Version specification |
|---|---|---|---|
| zip (x86) | Layer Datadog-Extension | Layer Datadog-<RUNTIME> | The number at the end of the ARN |
| zip (arm64) | Layer Datadog-Extension-ARM | Layer Datadog-<RUNTIME>-ARM | The number at the end of the ARN |
| Container image | Copy from the public image to /opt in the Dockerfile | Add as a dependency with pip | The image tag and the package version |
Because container image functions cannot use layers, add the library as a dependency with pip install datadog-lambda, and copy the Extension into the image by adding the following line to the Dockerfile.
COPY --from=public.ecr.aws/datadog/lambda-extension:<TAG> /opt/. /opt/For the tag you can write a version number or latest, and for Alpine there are tags with -alpine appended. The library package's minor version matches the layer version, so v0.5.0 of datadog-lambda has the same contents as layer version 5. Teams that mix zip functions and image functions can use this correspondence to align the versions of both.
Pin the version by number and decide for yourself when to upgrade
A Lambda layer is a snapshot whose contents do not change for each published version, and when you add one to a function, you are required to specify it down to the version number (source: Managing Lambda dependencies with layers). Once you write the number in the ARN, the contents of the Extension the function uses are fixed. What to watch out for is passing latest to a tool. The datadog-ci documentation lists by number the versions used when you pass latest to -e, which specifies the Extension version, and -v, which specifies the library version, and those numbers do not match the examples on the Python procedure page (as of October 2026; source: Datadog Serverless CLI). The version latest points to is determined by the value written into your copy of datadog-ci, so if the datadog-ci versions differ between your machine and CI, the same latest installs different Extensions.
| Version | What changes | What to check before upgrading |
|---|---|---|
| v67 to v87 | Bundles a next-generation version with shorter cold starts and the conventional compatibility version | Setting DD_EXTENSION_VERSION to compatibility lets you return to the compatibility version |
| v88 and later | Only the next-generation version remains | The escape route back to the compatibility version is gone. Periodic reloading of the API key becomes available |
| v90 and later | Supports running on Lambda Managed Instances | The Extension detects the execution mode automatically |
The official documentation recommends staying on new releases and advises reading the releases and changelog before upgrading (source: Datadog Lambda Extension). Pinning does not mean leaving it alone; it is a practice of deciding the day to upgrade and rewriting the numbers in order, starting from the test environment. The same applies when moving from x86 to arm64: if integrations such as API Gateway do not point to a version or alias of the function, the function can become unavailable for about 10 seconds during deployment.
Passing the API key as a Secrets Manager ARN is the standard form
The Extension needs an API key to send data. What the official documentation recommends is storing the key in AWS Secrets Manager and writing its ARN in DD_API_KEY_SECRET_ARN, citing security and ease of rotation as the reasons. Store the secret as a plaintext string, not JSON, and give the function's execution role the secretsmanager:GetSecretValue permission (as of October 2026; source: Instrumenting Python Serverless Applications). DD_API_KEY, which writes the key in plaintext in an environment variable, is a form for quick trials, and there is also DD_KMS_API_KEY, which passes a key encrypted with KMS.
| Method | Function environment variable | What is needed | When specified together |
|---|---|---|---|
| Secrets Manager | DD_API_KEY_SECRET_ARN | A plaintext string secret and the GetSecretValue permission | Ignored if DD_KMS_API_KEY is present |
| Encrypted with KMS | DD_KMS_API_KEY | A key encrypted with KMS | Takes precedence over the other two |
| Plaintext | DD_API_KEY | None (for quick trials) | Ignored if DD_KMS_API_KEY is present |
Build key rotation into the design from the start, too. With Extension v88 and later, if you write a number of seconds in DD_API_KEY_SECRET_RELOAD_INTERVAL, the Extension rereads the secret when it needs the key for sending, once the specified number of seconds has passed since the last read. The official example is a practice of rotating the key every day (86400 seconds) and keeping the old key valid for only one day, with the interval set to 43200 seconds so that the Extension moves to the new key within the grace period (source: Configure Serverless Monitoring for AWS Lambda). For the destination, write in DD_SITE the same Datadog site as the organization where the key was created.
The environment variable table and replacing the handler
After the key come the function's environment variables. When collecting with the Extension, the reserved tags env / service / version are set with the environment variables DD_ENV / DD_SERVICE / DD_VERSION. Values written in Lambda resource tags are attached as custom tags through the AWS integration with a delay of several minutes, and they do not substitute for reserved tags (as of October 2026; source: Configure Serverless Monitoring for AWS Lambda). Why the three values should be aligned across traces, logs, and metrics is explained in Unified Service Tagging.
| Environment variable | Value to write | Role |
|---|---|---|
| DD_SITE | The organization's Datadog site | Destination |
| DD_API_KEY_SECRET_ARN | The ARN of the secret | Where the API key is retrieved from |
| DD_ENV / DD_SERVICE / DD_VERSION | Environment, service name, version | Reserved tags |
| DD_TRACE_ENABLED | true | Sending traces |
| DD_LAMBDA_HANDLER | The original handler (for example: myfunc.handler) | What is called after the replacement |
| DD_TAGS | key:value separated by commas | Tags other than the reserved tags |
| DD_CAPTURE_LAMBDA_PAYLOAD | true | Captures the request and response bodies |
In Python, replace the handler with datadog_lambda.handler.handler and write the original handler in DD_LAMBDA_HANDLER. Datadog's processing is called first and then calls the original function; for container images, set CMD to this value. The setting that captures request bodies applies to Python, Node.js, Go, Java, and .NET, and for APIs that carry personal information, use it together with settings that narrow the fields captured. On the other hand, DD_AGENT_HOST and DD_TRACE_AGENT_URL are variables that are not set in serverless environments. When you copy APM settings meant for hosts or containers and add them to a function, check that these two have not slipped in.
Choose the tool to install with based on who owns the deployment
Besides writing it by hand, you can also apply the same configuration with tools Datadog provides. datadog-ci's lambda instrument rewrites an existing function's configuration without a new deployment, so it is the quickest way to try the first function. In production, however, the recommended form is to run this command within CI/CD after the normal deployment (as of October 2026; source: Instrumenting Python Serverless Applications). If your functions are already defined with the Serverless Framework, SAM, or Terraform, declaring the Datadog configuration within that definition keeps the versions and environment variables in one place.
| Tool | How to install | Extension version |
|---|---|---|
| datadog-ci | Run lambda instrument against existing functions | -e (the library uses -v) |
| Serverless Framework | Add serverless-plugin-datadog. The Extension is included by default | Plugin configuration |
| AWS SAM | Install the CloudFormation macro once per region and add DatadogServerless to Transform | extensionLayerVersion |
| AWS CDK | Use datadog-cdk-constructs-v2 | extensionLayerVersion |
| Terraform | Replace aws_lambda_function with the lambda-datadog module | datadog_extension_layer_version |
The form for trying it with datadog-ci is as follows, where -f is the function name and -r is the region.
datadog-ci lambda instrument -f <functionname> -r <aws_region> -v <version> -e <version>If the results are not what you hoped, running uninstrument with the same arguments removes Datadog's layers and configuration. The Terraform module accepts the arguments of aws_lambda_function as they are, and only the arguments written as blocks change into variables (for example: the variables in environment become environment_variables). When moving an existing definition, rewriting just this difference is enough.
For functions moving from the Forwarder, remove the log subscription first and go one at a time
When you add the Extension to a function that was sending logs with the Forwarder, the same logs may arrive over two paths. Because the Extension has log collection enabled by default, you need to remove the subscription filter that routes from the log group to the Datadog Forwarder (as of October 2026; source: Configure Serverless Monitoring for AWS Lambda). However, the Forwarder itself does not necessarily become unnecessary; its role in collecting logs from services other than Lambda is as described in the explanation of Serverless Monitoring. For a setup that collects only logs from many functions, keeping the Forwarder can also be a reasonable decision (source: Deciding to migrate to the Datadog Lambda extension).
- 1. Migrate functions in the development and test environments first, and proceed one function at a time in production
- 2. Upgrade the library layer and add the Extension layer. With datadog-ci, remove the --forwarder argument
- 3. Write DD_SITE and DD_API_KEY_SECRET_ARN, and move env / service / version from resource tags to environment variables
- 4. Remove the subscription filter to the Forwarder from that function's log group
- 5. Only after migrating all functions in the region, stop the Forwarder's automatic subscription through the AWS integration
How logs and traces are connected also changes: the Extension links the two by the AWS Lambda request ID, while the Forwarder links them by the Datadog trace ID. Invoke a migrated function once in the test environment and check whether the function appears on the Serverless screen and whether you can jump from a trace to the logs for the same request. If it does not appear, set DD_LOG_LEVEL to debug and read the Extension's logs. How execution time looks can be checked in the section on the Extension and slowness in the same explanation. Finally, if you decide the Extension and library versions for your functions one by one as numbers, write them in the ARNs, and keep a list of which function is on which version, the scope of work for the next upgrade day is determined as is.