DEV Community

Cover image for Dynatrace AWS integration: CloudWatch metrics and logs step by step
Span Observer
Span Observer

Posted on Originally published at span.observer

Dynatrace AWS integration: CloudWatch metrics and logs step by step

Your workloads run on EC2, RDS and Lambda, yet the on-call engineer still switches between the CloudWatch console and Dynatrace. A Dynatrace AWS integration brings CloudWatch metrics and logs into one place, next to the traces and entities OneAgent has already discovered.

That split has a real cost: every tool switch lengthens MTTR, and a saturated RDS instance stays invisible to your SLOs until its metrics are correlated with the service that depends on it. A clean integration closes that coverage gap.

The goal of this tutorial: connect an AWS account through a read-only IAM role, stream CloudWatch log groups to Dynatrace through Amazon Data Firehose, and check the result in DQL. The content applies to Dynatrace SaaS; differences for Dynatrace Managed are flagged at each step.

What the Dynatrace AWS integration covers

The integration relies on two separate flows. Mixing them up is the first source of support tickets.

Flow Mechanism What lands in Dynatrace
Metrics and metadata Dynatrace polls the CloudWatch API by assuming an IAM role in your account AWS service metrics, entities (instances, databases, functions), tags
Logs A CloudWatch Logs subscription pushes to an Amazon Data Firehose stream, which sends to the log ingest API Log records in Grail, with the source log group

The first flow is pull: Dynatrace reads. The second is push: AWS sends. Permissions differ, and a fault in one never explains a gap in the other.

Prerequisites

  • An AWS account with rights to create IAM roles and CloudFormation stacks (AWS CLI configured, or CloudShell).
  • A Dynatrace SaaS environment and permission to change environment settings.
  • A Dynatrace API token with the log ingest scope (logs.ingest, shown as « Ingest logs »), kept in a variable and never in a repository.
  • On Managed: an ActiveGate that can reach AWS, since it is the component that polls CloudWatch, and a log ingest URL routed through that ActiveGate.

Step 1: create the monitoring IAM role

Dynatrace does not need a long-lived access key: it assumes a role through sts:AssumeRole, guarded by an external ID. When you create the AWS connection in the Dynatrace settings, the screen gives you that ID. Copy it before switching to AWS.

Then create the role’s trust policy. The Dynatrace AWS account below is the one given in the SaaS documentation; check it against your connection screen, which is authoritative.

cat > trust.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::314146291599:root" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": { "sts:ExternalId": "<external-id-from-dynatrace>" }
      }
    }
  ]
}
EOF

aws iam create-role \
  --role-name DynatraceMonitoringRole \
  --assume-role-policy-document file://trust.json
Enter fullscreen mode Exit fullscreen mode

The critical line is the sts:ExternalId condition: without it, any other customer of the same provider could try to assume your role (the « confused deputy » problem). Never remove it to « unblock » a connection.

On Managed, the principal is not the Dynatrace account: it is the role attached to the ActiveGate running in AWS. Follow the Managed procedure in the documentation for the account and role name to trust.

Step 2: grant CloudWatch read access

Attach a read-only policy to the role. The minimal base fits in a few actions; the documentation provides a complete policy per monitored service.

cat > policy.json <<'EOF'
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "cloudwatch:GetMetricData",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:ListMetrics",
        "sts:GetCallerIdentity",
        "tag:GetResources",
        "tag:GetTagKeys",
        "ec2:DescribeAvailabilityZones",
        "ec2:DescribeInstances",
        "rds:DescribeDBInstances",
        "lambda:ListFunctions",
        "lambda:ListTags"
      ],
      "Resource": "*"
    }
  ]
}
EOF

aws iam put-role-policy \
  --role-name DynatraceMonitoringRole \
  --policy-name DynatraceMonitoringPolicy \
  --policy-document file://policy.json
Enter fullscreen mode Exit fullscreen mode

The tag:* actions matter more than they seem: without them AWS tags are not imported, and you lose the per-team or per-environment filtering that later drives alert routing.

Step 3: complete the connection and pick services

Back in Dynatrace, paste the role ARN and the AWS account ID, then save. Select the services to monitor and, if needed, restrict collection by region or tag. Start small: EC2, RDS, Lambda and load balancers cover most incidents.

Each extra service multiplies CloudWatch API calls, billed by AWS, and the metric volume in Dynatrace. Tag filtering (for example monitoring=dynatrace) avoids paying for sandbox resources.

Step 4: stream CloudWatch logs through Data Firehose

Dynatrace publishes a CloudFormation template that creates the Firehose stream, the S3 backup bucket for failed deliveries and the role used by subscriptions. Deploy it from a shell with the AWS CLI or from CloudShell:

DYNATRACE_API_URL=https://<environment-id>.live.dynatrace.com
DYNATRACE_API_KEY=<logs-ingest-token>
STACK_NAME=dynatrace-log-delivery-stream

wget -O dynatrace-firehose-log-stream.yaml \
  https://assets.cloud.dynatrace.com/awslogstreaming/dynatrace-firehose-log-stream.yaml

aws cloudformation deploy \
  --capabilities CAPABILITY_NAMED_IAM \
  --template-file ./dynatrace-firehose-log-stream.yaml \
  --stack-name $STACK_NAME \
  --parameter-overrides DtApiUrl=$DYNATRACE_API_URL DtApiToken=$DYNATRACE_API_KEY
Enter fullscreen mode Exit fullscreen mode

On Managed or behind an ActiveGate, the URL looks like https://<activegate>/e/<environment-id>. Firehose only delivers to an HTTPS endpoint with a valid certificate: an ActiveGate with a self-signed certificate will be rejected.

Next, subscribe the log groups you need with the script Dynatrace provides:

wget -O dynatrace-firehose-logs.sh \
  https://assets.cloud.dynatrace.com/awslogstreaming/dynatrace-firehose-logs.sh
chmod +x dynatrace-firehose-logs.sh

./dynatrace-firehose-logs.sh subscribe \
  --log-groups /aws/lambda/checkout /aws/rds/instance/orders/postgresql \
  --stack-name $STACK_NAME \
  --filter-pattern "?ERROR ?WARN"
Enter fullscreen mode Exit fullscreen mode

--filter-pattern is your first cost lever: it filters at the source, before Firehose. Without it the whole log group is shipped, debug noise included. Note that CloudWatch caps the number of subscription filters per log group: if another tool already uses them, the script returns a LimitExceededException.

How to check it works

On the AWS side, open the CloudFormation stack: the Events tab must show no failure, and the Outputs tab gives the Firehose stream ARN. In the stream’s metrics, DeliveryToHttpEndpoint.Success should sit close to 1.

On the Dynatrace side, open a notebook and check logs first, group by group:

fetch logs, from: now() - 1h
| filter isNotNull(aws.log_group)
| summarize count(), by: {aws.log_group}
Enter fullscreen mode Exit fullscreen mode

Then metrics, for example RDS instance CPU:

timeseries avg(dt.cloud.aws.rds.cpu.usage)
Enter fullscreen mode Exit fullscreen mode

CloudWatch metrics arrive a few minutes late, because CloudWatch itself publishes them with a delay. An empty chart after five minutes is not a failure; after thirty, re-read the IAM policy. For more checks, see our DQL query examples for operations.

Good practices

  • One IAM role per AWS account, named the same everywhere: troubleshooting becomes mechanical.
  • Filter by tag and region from day one rather than enabling everything and cutting back later.
  • Keep the Firehose S3 backup bucket and watch its size: it grows when ingestion fails.
  • Rotate the ingest token and update the stack parameter; on a 401, follow our guide to troubleshoot a Dynatrace API token.
  • Alert on missing logs from a critical group, not only on errors: see detecting silence in log ingestion.

Frequently asked questions

Do I still need OneAgent when the AWS integration is active?

Yes, for hosts and applications. The CloudWatch integration sees resources from the outside, at CloudWatch granularity. OneAgent provides processes, distributed traces and fine-grained metrics. The two complement each other: Dynatrace links the EC2 instance seen through CloudWatch to the host seen by OneAgent.

What changes between SaaS and Managed for this integration?

On SaaS, Dynatrace polls AWS from its own infrastructure and the role trusts its account. On Managed, your ActiveGate polls AWS: it must run in AWS for role-based authentication, and Firehose logs go through an ActiveGate URL with a valid certificate. To choose the ActiveGate, see Environment ActiveGate or Cluster ActiveGate.

Why do some log groups never arrive?

Three causes come up: the group is not subscribed (check subscription filters in CloudWatch), the filter pattern excludes everything, or Firehose fails to reach Dynatrace and drops batches into the S3 backup bucket. Start with that bucket: if it holds recent files, the problem is the token or the URL.

Conclusion

A read-only IAM role, a Firehose stack and a few subscriptions are enough to bring CloudWatch into Dynatrace. The benefit is not the number of charts but correlation: the saturated RDS instance finally shows up next to the slow service, and on-call searches in a single tool. Start with two or three critical services, check in DQL, then widen. The reference procedure lives on docs.dynatrace.com.

span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of its owner. Screen names and procedures change: always check the official documentation before a production change.


Originally published on span.observer. French version: https://span.observer/fr/dynatrace-aws-cloudwatch-metriques-logs/.

Top comments (0)