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

Four things that differ between the EC2 launch type and Fargate (as of September 2026)
AspectEC2 launch typeFargate
DeploymentA dedicated Agent task definition run as a daemon service, one per instanceAn Agent container added to the application's task definition (sidecar)
What can be collectedThe host and every container on that instance. Running tasks are detected with AutodiscoveryCPU / memory of containers in the same task, plus integration metrics. There is no concept of a host
Log routeThe Agent container collects stdout / stderr on the same hostSend directly with FireLens (Fluent Bit), or awslogs → CloudWatch Logs → Forwarder
APM routeFrom 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
Sources: Amazon ECS / Amazon ECS on AWS Fargate / Tracing ECS Applications

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
Source: steps extracted by the author from the Manual setup section of Amazon ECS

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

Values to write in the Fargate task definition and their roles (as of September 2026)
Where to write itValueRole
Agent container environment variablesDD_API_KEY / ECS_FARGATE=true / DD_SITEThe key, enabling Fargate mode, and the destination site
Agent container environment variablesDD_APM_ENABLED=trueReceive traces from the application in the same task
Agent container environment variablesDD_DOCKER_LABELS_AS_TAGSConvert other containers' labels into tags. Officially recommended for tagging overall
Task definitionTask execution IAM rolePulling the Agent image and referencing secrets
IAM policy for the Datadog AWS integrationecs:ListClusters / ecs:ListContainerInstances / ecs:DescribeContainerInstancesSupplementing Fargate metrics (the four permissions on the ECS integration side are described later)
Value not to writeDD_HOSTNAMEFargate has no concept of a host, and setting it makes the task appear in the list as an APM host
Source: the Installation / Other environment variables sections of Amazon ECS on AWS Fargate

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

The three ECS log routes and the situations they suit (as of September 2026)
RouteMechanismSuited to
Via the AgentThe 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
FireLensA Fluent Bit log router container (amazon/aws-for-fluent-bit) is placed in the same task and sends directly with the Datadog output pluginFargate. Officially recommended. Tags are attached from ECS metadata
awslogs + ForwarderOutput to CloudWatch Logs and forwarded by the Datadog Forwarder LambdaEnvironments already aggregating into CloudWatch Logs. Naming the log group /ecs/cluster-name gets tags filled in
Sources: Amazon ECS Log Collection / the Log collection section of Amazon ECS on AWS Fargate

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

Three forms for delivering traces to the Agent (as of September 2026)
FormWhat to write on the Agent sideWhat to write on the application side
EC2 launch type - Unix domain socketShare /var/run/datadog/apm.socket with the application via a volumeunix:///var/run/datadog/apm.socket in DD_TRACE_AGENT_URL
EC2 launch type - TCP/IPSet DD_APM_ENABLED and DD_APM_NON_LOCAL_TRAFFIC to true and map port 8126The instance's private IP in DD_AGENT_HOST (obtained from local-ipv4 in the metadata)
Fargate - sidecarDD_APM_ENABLED=trueNothing (reaches via the localhost default)
Sources: Tracing ECS Applications / the Trace collection section of Amazon ECS on AWS Fargate

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.

Symptoms that trip you up on ECS / Fargate and where to look (as of September 2026)
SymptomCandidate causesWhere to look
No metrics on FargateECS_FARGATE is missing, or the Agent is in a different taskWhether the Agent container is in the same task definition with ECS_FARGATE=true attached
The Agent runs but nothing appears on screenDD_SITE is unset and data goes to US1Whether the organization's login URL matches DD_SITE
Tasks appear in the host list and the counts do not add upDD_HOSTNAME was set on FargateRemove DD_HOSTNAME from the Agent container's environment variables
Traces do not arrive on the EC2 launch typeThe IP or socket reaching the Agent is not being passed, or port 8126 is closedDD_AGENT_HOST or DD_TRACE_AGENT_URL, and DD_APM_NON_LOCAL_TRAFFIC on the Agent side
Only logs do not arriveYou are trying to pick up awslogs driver logs with the AgentSwitch the route to FireLens or the Forwarder
Tags are not attachedThe label specified in DD_DOCKER_LABELS_AS_TAGS is not on the application-side containerdockerLabels in the application-side container definition
Sources: Amazon ECS on AWS Fargate / Amazon ECS / Tracing ECS Applications

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.

References

Share