1. Answers
  2. Integrate Dynatrace with Amazon ECS

How do I use Dynatrace with Amazon ECS?

To integrate Dynatrace with Amazon ECS, you’ll set up an ECS cluster and deploy the Dynatrace OneAgent as a sidecar container within your ECS task definitions. The following example demonstrates how to achieve this setup.

This example includes:

  1. Creating an ECS cluster.
  2. Defining a task definition with the Dynatrace OneAgent sidecar container.
  3. Running an ECS service with tasks that include Dynatrace monitoring.

Below is the complete example:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.ecs.Cluster("example", {name: "example"});
const ecsTaskExecution = new aws.iam.Role("ecs_task_execution", {
    name: "ecsTaskExecutionRole",
    assumeRolePolicy: `{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Effect": "Allow",
      "Principal": {
        "Service": "ecs-tasks.amazonaws.com"
      }
    }
  ]
}
`,
});
const ecsTaskExecutionPolicy = new aws.iam.RolePolicyAttachment("ecs_task_execution_policy", {
    role: ecsTaskExecution.name,
    policyArn: "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy",
});
const exampleTaskDefinition = new aws.ecs.TaskDefinition("example", {
    family: "example",
    networkMode: "awsvpc",
    requiresCompatibilities: ["FARGATE"],
    memory: "512",
    cpu: "256",
    executionRoleArn: ecsTaskExecution.arn,
    containerDefinitions: JSON.stringify([
        {
            name: "my-app",
            image: "amazon/amazon-ecs-sample",
            essential: true,
            portMappings: [{
                containerPort: 80,
                hostPort: 80,
            }],
        },
        {
            name: "dynatrace-oneagent",
            image: "docker.io/dynatrace/oneagent:latest",
            essential: false,
            environment: [
                {
                    name: "ONEAGENT_ENVIRONMENT_ID",
                    value: "example-environment-id",
                },
                {
                    name: "ONEAGENT_API_URL",
                    value: "https://<tenant>.dynatrace.com/api",
                },
                {
                    name: "ONEAGENT_API_TOKEN",
                    value: "your-dynatrace-api-token",
                },
            ],
        },
    ]),
});
const exampleService = new aws.ecs.Service("example", {
    name: "example",
    cluster: example.id,
    taskDefinition: exampleTaskDefinition.arn,
    desiredCount: 1,
    networkConfiguration: {
        subnets: ["subnet-0123456789abcdef0"],
        securityGroups: ["sg-0123456789abcdef0"],
    },
});
export const ecsClusterName = example.name;
export const ecsServiceName = exampleService.name;
export const ecsTaskDefinitionArn = exampleTaskDefinition.arn;

This program demonstrates how to set up an ECS cluster with a task definition that includes the Dynatrace OneAgent sidecar. Follow these steps to monitor your ECS application with Dynatrace, ensuring your application’s performance is tracked efficiently.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up