Teratip: How to monitor an ECS task running on Fargate with Datadog

Let’s say you already have Datadog configured to monitor your workloads in AWS and you want to get more insights from some ECS tasks running on Fargate. In order to do that, you will need to add the Datadog Agent to your task as a sidecar container -i.e. an additional container that runs alongside the application container.
Below is an example of the container definitions block of an ECS task definition. The first container is a custom application and the second one is the Datadog Agent:
[
{
"name": "post-migrations-production",
"cpu": ${cpu_units},
"memory": ${max_memory},
"memoryReservation": ${min_memory},
"image": "${ecr_repo}",
"essential": true,
"environment": [
{
"name": "DD_SERVICE_NAME",
"value": "post-migrations"
}
],
},
{
"name": "datadog-agent",
"image": "public.ecr.aws/datadog/agent:latest",
"environment": [
{
"name": "ECS_FARGATE",
"value": "true"
},
{
"name": "DD_API_KEY",
"value": "xxxxxxxxx