Running the Datadog Agent on ECS / Fargate - Deployment Patterns
When running the Datadog Agent on Amazon ECS, the deployment pattern splits first: a daemon per instance on the EC2 launch type, and a sidecar inside the task on Fargate. The routes for logs and APM are determined by that pattern too. This article organizes, pattern by pattern, the values to write in the task definition, IAM, the three log routes, and where things trip you up.
Two deployment patterns, and every route that follows is decided by the pattern
The way to run the Datadog Agent on Amazon ECS splits in two by launch type. On the EC2 launch type, you run the Agent task definition as a daemon service and place one Agent container on each EC2 instance in the cluster. On Fargate, you add an Agent container to the very task definition you want to monitor, running it as a sidecar in the same task as the application containers. The reason it takes this form on Fargate is that the ECS task metadata endpoint from which the Agent obtains metrics is reachable only from inside the task (as of September 2026; sources: Amazon ECS / Amazon ECS on AWS Fargate).
| Aspect | EC2 launch type | Fargate |
|---|---|---|
| Deployment | A dedicated Agent task definition run as a daemon service, one per instance | An Agent container added to the application's task definition (sidecar) |
| What can be collected | The host and every container on that instance. Running tasks are detected with Autodiscovery | CPU / memory of containers in the same task, plus integration metrics. There is no concept of a host |
| Log route | The Agent container collects stdout / stderr on the same host | Send directly with FireLens (Fluent Bit), or awslogs → CloudWatch Logs → Forwarder |
| APM route | From the application to the Agent on the instance (Unix socket or TCP 8126) | To the Agent in the same task. DD_AGENT_HOST stays at the default localhost |
Once you decide which column of this table to proceed down, the remaining decisions simply follow that column. Note that how containers and tasks are counted for pricing is not covered in this article; it is left to the counting sections in the Container Monitoring and Serverless Monitoring explanations.
On the EC2 launch type, create one task definition and distribute it as a daemon
The EC2 launch type procedure has three steps, "create the task definition → register it → run it as a daemon service," and the official page provides both a path that proceeds from Fleet Automation and a manual path. For the manual path, the officially distributed datadog-agent-ecs.json serves as the base, with separate files provided for Amazon Linux 1 and Windows (as of September 2026; source: Amazon ECS).
- 1. Edit the task definition - write DD_API_KEY (a Secrets Manager secret ARN is also accepted), DD_SITE, and optionally DD_TAGS as environment variables
- 2. Register - import it with aws ecs register-task-definition or via "Create new task definition with JSON" in the console
- 3. Create the daemon service - under the cluster's Services, set Service type to Daemon. No load balancer or autoscaling is needed
The value that is easy to overlook in the task definition is DD_SITE; if you leave it out, data is sent to US1 (datadoghq.com). In organizations on a different site, this shows up as the Agent running fine while nothing appears on your own screens. If you are distributing to an ECS Anywhere cluster, add EXTERNAL to requiresCompatibilities, and if you want a health check on the Agent, you can write a healthCheck with agent health as the command. Since changing the Agent's configuration means updating this task definition and then updating the service, keeping the task definition file under version control makes life easier later.
Fargate is decided by the sidecar's environment variables and IAM
On Fargate, you add an Agent container to the application's task definition. In the official page's procedure, the container name is datadog-agent, the image is public.ecr.aws/datadog/agent:latest, and the environment variables are DD_API_KEY, ECS_FARGATE set to true, and DD_SITE. Without ECS_FARGATE, metric collection does not start, so it is the first value to check on the Fargate side (as of September 2026; source: Amazon ECS on AWS Fargate).
| Where to write it | Value | Role |
|---|---|---|
| Agent container environment variables | DD_API_KEY / ECS_FARGATE=true / DD_SITE | The key, enabling Fargate mode, and the destination site |
| Agent container environment variables | DD_APM_ENABLED=true | Receive traces from the application in the same task |
| Agent container environment variables | DD_DOCKER_LABELS_AS_TAGS | Convert other containers' labels into tags. Officially recommended for tagging overall |
| Task definition | Task execution IAM role | Pulling the Agent image and referencing secrets |
| IAM policy for the Datadog AWS integration | ecs:ListClusters / ecs:ListContainerInstances / ecs:DescribeContainerInstances | Supplementing Fargate metrics (the four permissions on the ECS integration side are described later) |
| Value not to write | DD_HOSTNAME | Fargate has no concept of a host, and setting it makes the task appear in the list as an APM host |
Instead of placing the key in plain text in an environment variable, the official page shows the form of referencing the ARN of a secret stored in AWS Secrets Manager. For tagging, the recommended form is to pick up labels from other containers with DD_DOCKER_LABELS_AS_TAGS, which comes with the premise that you attach the labels you want picked up to the application-side containers. Custom metrics are received by the Agent in the same task over DogStatsD on UDP 8125.
There are three log routes, and the Agent only sees standard output on the same host
Log routes split by launch type, and choosing the wrong one traps you in the form of "metrics show up but logs do not arrive." On the EC2 launch type, the recommended form is for the Agent container to collect the stdout / stderr of other containers on the same host: add DD_LOGS_ENABLED and DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL to the Agent task definition and add mounts such as /var/lib/docker/containers. On the other hand, if the application side sends to CloudWatch Logs with the awslogs driver, those logs are not visible to the Agent (as of September 2026; source: Amazon ECS Log Collection).
| Route | Mechanism | Suited to |
|---|---|---|
| Via the Agent | The Agent container collects stdout / stderr on the same host (default / json-file driver) | EC2 launch type. Logs written to files inside containers need additional configuration |
| FireLens | A Fluent Bit log router container (amazon/aws-for-fluent-bit) is placed in the same task and sends directly with the Datadog output plugin | Fargate. Officially recommended. Tags are attached from ECS metadata |
| awslogs + Forwarder | Output to CloudWatch Logs and forwarded by the Datadog Forwarder Lambda | Environments already aggregating into CloudWatch Logs. Naming the log group /ecs/cluster-name gets tags filled in |
As reasons for recommending FireLens on Fargate, the official page cites the ability to configure Fluent Bit directly within the task definition, and the fact that the tags attached by the Datadog output plugin link logs to resources in the ECS Explorer. The route using the Datadog Forwarder needs to be considered together with the AWS integration setup, and that sequence is covered in the AWS integration article.
Where to send APM traces - socket, IP, and localhost
Where people stumble with APM is not the instrumentation itself but "how to get traces from the application container to the Agent." On the EC2 launch type, the Agent is a separate container, so the destination must be specified explicitly, and the official page lists two routes: a Unix domain socket and TCP/IP (as of September 2026; source: Tracing ECS Applications). On Fargate, conversely, the right answer is to specify nothing: just add DD_APM_ENABLED set to true to the Agent container. Because it is the same task, the default localhost reaches the Agent as is, and the official page notes that DD_AGENT_HOST should not be set on Fargate (source: Amazon ECS on AWS Fargate).
| Form | What to write on the Agent side | What to write on the application side |
|---|---|---|
| EC2 launch type - Unix domain socket | Share /var/run/datadog/apm.socket with the application via a volume | unix:///var/run/datadog/apm.socket in DD_TRACE_AGENT_URL |
| EC2 launch type - TCP/IP | Set DD_APM_ENABLED and DD_APM_NON_LOCAL_TRAFFIC to true and map port 8126 | The instance's private IP in DD_AGENT_HOST (obtained from local-ipv4 in the metadata) |
| Fargate - sidecar | DD_APM_ENABLED=true | Nothing (reaches via the localhost default) |
For languages such as Java and .NET that read variables at startup, the official example is to obtain the IP from the metadata and put it into an environment variable as a step before the startup command. When delivering from an application in awsvpc mode on the EC2 launch type, the official advice is that running the Agent itself in bridge mode with the port exposed saves the trouble of looking up the ENI's IP (source: the AWSVPC mode section of Amazon ECS).
The AWS-side ECS integration and the Agent: which sees what
For ECS monitoring, apart from the Agent, there is the ECS integration within the AWS integration. It is a mechanism in which Datadog fetches CloudWatch metrics, and even tasks without the Agent have their CPU and memory utilization arrive as metrics beginning with aws.ecs.. Enabling it is just a matter of checking ECS under Metric Collection on the AWS integration tile and adding four ecs permissions such as ecs:ListClusters and ecs:ListServices to the IAM policy (as of September 2026; source: Amazon ECS Integration). The division of labor is "the big picture via CloudWatch, deep dives via the Agent." The official Fargate page also states explicitly that CloudWatch metrics are coarse-grained (1 to 5 minutes) and delayed, and are fetched every 10 minutes by default, so the Agent is required for detailed container metrics and traces.
Where to look when no metrics, containers, or tags appear
When you have finished configuring and nothing shows on screen, the causes are scattered across each stage of the route, but the order in which to check is fixed.
| Symptom | Candidate causes | Where to look |
|---|---|---|
| No metrics on Fargate | ECS_FARGATE is missing, or the Agent is in a different task | Whether the Agent container is in the same task definition with ECS_FARGATE=true attached |
| The Agent runs but nothing appears on screen | DD_SITE is unset and data goes to US1 | Whether the organization's login URL matches DD_SITE |
| Tasks appear in the host list and the counts do not add up | DD_HOSTNAME was set on Fargate | Remove DD_HOSTNAME from the Agent container's environment variables |
| Traces do not arrive on the EC2 launch type | The IP or socket reaching the Agent is not being passed, or port 8126 is closed | DD_AGENT_HOST or DD_TRACE_AGENT_URL, and DD_APM_NON_LOCAL_TRAFFIC on the Agent side |
| Only logs do not arrive | You are trying to pick up awslogs driver logs with the Agent | Switch the route to FireLens or the Forwarder |
| Tags are not attached | The label specified in DD_DOCKER_LABELS_AS_TAGS is not on the application-side container | dockerLabels in the application-side container definition |
The signs of success are, on the EC2 launch type, one Agent task running on each instance and tasks picked up by Autodiscovery lined up in the container list; on Fargate, the Agent container in the task has started and the CPU and memory of the containers in the same task are visible. The official page says Agent 6.1.1 or later is required to make full use of the Fargate integration, so in environments pinned to an old image, check that as well. How to run the Agent on Docker alone, and the way of thinking about the environment variables it shares, are covered in the Docker article.