ECS Task Definition (examples)

๐Ÿ“˜

Service Maps is an Enterprise-only feature

Option 1: Datadog Dual Shipping (Recommended)

Example Task Definition for datadog-agent container. You want to run this as a DAEMON service, one per EC2 host.

There are 2 environment keys you want to update. You can store its value at SSM Param Storage or AWS Secret Manager.

  1. DD_API_KEY: The Datadog API key used to send your data directly to Datadog.
  2. DD_APM_ADDITIONAL_ENDPOINTS: This will define additional endpoint to send data to CodeSee. Example value: {"https://in-datadog.codesee.io": ["<CodeSee Ingestion Token here>"]}
{
    "containerDefinitions": [
        {
            "name": "datadog-agent",
            "image": "datadog/agent:latest",
            "cpu": 100,
            "memory": 512,
            "portMappings": [
                {
                    "containerPort": 8125,
                    "hostPort": 8125,
                    "protocol": "udp"
                },
                {
                    "containerPort": 8126,
                    "hostPort": 8126,
                    "protocol": "tcp"
                }
            ],
            "essential": true,
            "environment": [
                {
                    "name": "DD_APM_NON_LOCAL_TRAFFIC",
                    "value": "true"
                },
                {
                    "name": "DD_PROCESS_AGENT_ENABLED",
                    "value": "true"
                },
                {
                    "name": "DD_APM_ENABLED",
                    "value": "true"
                },
                {
                    "name": "DD_LOGS_ENABLED",
                    "value": "true"
                },
                {
                    "name": "DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL",
                    "value": "true"
                },
                {
                    "name": "DD_DOGSTATSD_NON_LOCAL_TRAFFIC",
                    "value": "true"
                },
                {
                    "name": "DD_CLOUD_PROVIDER_METADATA",
                    "value": "aws"
                }
            ],
            "mountPoints": [
                {
                    "sourceVolume": "docker_sock",
                    "containerPath": "/var/run/docker.sock"
                },
                {
                    "sourceVolume": "cgroup",
                    "containerPath": "/host/sys/fs/cgroup"
                },
                {
                    "sourceVolume": "proc",
                    "containerPath": "/host/proc"
                },
                {
                    "sourceVolume": "pointdir",
                    "containerPath": "/opt/datadog-agent/run",
                    "readOnly": false
                },
                {
                    "sourceVolume": "containers_root",
                    "containerPath": "/var/lib/docker/containers",
                    "readOnly": true
                }
            ],
            "volumesFrom": [],
            "secrets": [
                {
                    "name": "DD_API_KEY",
                    "valueFrom": "<ARN to your SSM or Secret Manager>"
                },
                {
                    "name": "DD_APM_ADDITIONAL_ENDPOINTS",
                    "valueFrom": "<ARN to your SSM or Secret Manager>"
                }
            ]
        }
    ],
    "family": "example-datadog-agent-task",
    "revision": 1,
    "volumes": [
        {
            "name": "cgroup",
            "host": {
                "sourcePath": "/sys/fs/cgroup/"
            }
        },
        {
            "name": "pointdir",
            "host": {
                "sourcePath": "/opt/datadog-agent/run"
            }
        },
        {
            "name": "proc",
            "host": {
                "sourcePath": "/proc/"
            }
        },
        {
            "name": "containers_root",
            "host": {
                "sourcePath": "/var/lib/docker/containers/"
            }
        },
        {
            "name": "docker_sock",
            "host": {
                "sourcePath": "/var/run/docker.sock"
            }
        }
    ]
}

Option 2: dd-bridge

Example Task Definition

{
    "containerDefinitions": [
        {
            "name": "dd-bridge",
            "image": "codeseeio/dd-bridge",
            "cpu": 50,
            "memory": 128,
            "portMappings": [
                {
                    "containerPort": 8080,
                    "hostPort": 8080,
                    "protocol": "tcp"
                }
            ],
            "essential": true,
            "environment": [
                {
                    "name": "CODESEE_BRIDGE_FORWARD_HOST",
                    "value": "https://in-datadog.codesee.io"
                }
            ],
            "mountPoints": [],
            "volumesFrom": [],
            "secrets": [
                {
                    "name": "CODESEE_BRIDGE_TOKEN",
                    "valueFrom": "<Your Ingestion Token from CodeSee>"
                }
            ]
        }
    ],
    "family": "<Family Name>",
    "revision": 5,
    "volumes": [],
    "status": "ACTIVE",
    "placementConstraints": [],
    "compatibilities": [
        "EXTERNAL",
        "EC2"
    ]
}

Example Terraform ECS Task Definition

resource "aws_ecs_task_definition" "dd_bridge" {
    family = "dd-bridge"
  
    container_definitions = jsonencode([
      {
        name          = "dd-bridge"
        image         = "codeseeio/dd-bridge"
        cpu           = 50
        memory        = 128
        essential     = true
        task_role_arn = aws_iam_role.dd_bridge_role.arn
  
        portMappings = [
          {
            hostPort      = 8080,
            protocol      = "tcp",
            containerPort = 8080
          }
        ]
  
        environment = [
          {
            name  = "CODESEE_BRIDGE_FORWARD_HOST",
            value = "https://in-datadog.codesee.io"
          }
        ]
  
        secrets = [
          {
            name      = "CODESEE_BRIDGE_TOKEN",
            valueFrom = "<CodeSee Ingestion Token>"
          },
        ]
      }
    ])
}