Adding Datadog to Medplum on ECS Fargate

Add a Datadog agent sidecar to a self-hosted Medplum running on ECS Fargate through the CDK additionalContainers setting, with the required environment variables and a safe API key process.

On this page

Adding Datadog to Medplum on ECS Fargate for container metrics

The Datadog agent runs as a sidecar container inside the same ECS task as Medplum, and you attach it through the additionalContainers property in your CDK configuration. This is the route the Medplum documentation describes as supported for AWS, so it is the path to plan around if your team already deploys Medplum with CDK and wants container metrics in Datadog without building a separate collection layer. The agent reads metrics from the containers in the task, which gives your on-call team a view of container behavior alongside the rest of the stack. Before you start, confirm with the current Medplum Datadog integration docs which container image tag and version the sidecar should use, because the image and its configuration keys can change between Medplum releases.

A team needs this when it wants container-level signals, such as CPU and memory use of the Medplum server containers, inside Datadog rather than only in CloudWatch or in a separate monitoring tool. It matters most when Datadog is already the place where your operations and security teams look for alerts, dashboards and incident history. It matters less if your monitoring plan is already complete in another system. Decide that before editing the stack, because adding a sidecar changes the task definition, which means every task restart and every new deployment carries the agent with it. Plan the change in a non-production environment first and note which containers and metrics you expect to see afterward.

The work is a change to your existing CDK app, not a new platform. You will edit the Fargate service definition, add the agent container with its required environment variables, and then apply the change with a normal CDK deployment, which replaces the running tasks. Your effort depends mainly on how many Medplum services you run, how your CDK code is organized and whether Datadog is already installed in the account. The sections that follow cover the setting, the environment variables, safe handling of the API key and the apply step in order.

Configuration choices and when each fits

This table compares the main choices for the Datadog API key, the DD_SITE value and later log or APM collection. Read each row against your team's secrets policy and how much operational work you can take on. The main takeaway is that the key source is the decision that most affects security review, while the other two mostly affect how much you run later.

ChoiceWhat it involvesWhen it fitsOperational effort
API key from AWS Secrets ManagerStore the key in Secrets Manager and reference it from the task definition so it is injected at launchMost regulated deployments, where secrets need audit trails, rotation and restricted IAM accessModerate: create the secret, grant the task execution role read access, and plan rotation with a redeploy
API key from SSM Parameter StoreStore the key as a SecureString parameter and reference it from the task definitionTeams that already manage configuration in SSM and want one place for parametersModerate: similar IAM work to Secrets Manager, with fewer built-in rotation features to rely on
Plain value in the CDK configWrite the key directly in the CDK code or environment blockOnly short-lived test stacks that never reach a shared repository or pipeline logLow to set up, but the key lands in source control and CloudFormation templates, which usually fails review
DD_SITE for your Datadog regionSet the site value so the agent sends data to the Datadog region where your account livesEvery deployment. The value must match the account's region or data will not arriveLow: confirm the site with your Datadog account owner before the first deploy
Metrics only at firstCollect container metrics through the agent sidecar and leave log and APM collection offTeams that need a quick signal on task health and resource use with the smallest change to the stackLow: one sidecar and a small set of environment variables to review and maintain
Logs or APM added laterEnable log collection or application tracing after the metrics path works, with changes to the task and application configTeams that need log search or request tracing and can plan an extra change windowHigher: each addition touches the task definition, adds data volume, and needs its own review of what gets sent

Setup sequence for the Datadog sidecar with CDK

This sequence takes a CDK-deployed Medplum from no Datadog collection to a Datadog agent sidecar that sends container metrics from the Fargate task. Each step ends with a check you can run before moving on.

  1. Confirm the Datadog account and site

    Sign in to the Datadog organization that will receive Medplum metrics and note its site, the region-specific hostname your account uses. Your platform or observability team usually owns this, so confirm it with them before any AWS change. The value you need is the site string that will be assigned to DD_SITE in a later step. You are done when you can name the site and confirm that the account is the one your operations team reads from. Ask the Datadog administrator to confirm that the account allows API keys for agent use.

  2. Create or retrieve a Datadog API key

    In Datadog, create an API key for the agent or retrieve an existing one that your organization has approved for this purpose. Give the key a name that identifies the Medplum environment so it can be revoked without affecting other agents. Keep the key value in your password manager or secure transfer channel only until it is stored in the secret store in the next step. You are done when the key appears in the Datadog API key list under the name you chose and you have the value in hand for the next step.

  3. Store the API key in a secret store

    Save the key in AWS Secrets Manager or another secret store your CDK stack can reference, in the same account and region as the Medplum deployment. Do not place the key in the CDK source, a container image, a committed .env file or a plain environment variable in your repository. Grant the ECS task execution role read access to that secret only, so the agent container can retrieve it at launch. You are done when the secret exists, the secret ARN is recorded for the CDK change, and a policy simulation or test read using the execution role succeeds.

  4. Add the additionalContainers entry

    In the CDK configuration for your Medplum server, add a Datadog agent entry under the additionalContainers property. Set DD_SITE to the site you confirmed, set DD_API_KEY from the secret reference rather than a literal value, and set ECS_FARGATE so the agent collects Fargate task metrics. Keep the changes limited to this entry and its environment settings. You are done when the file diffs cleanly, the key value does not appear anywhere in the diff, and a code review confirms that all three required settings are present.

  5. Run cdk diff and review the changes

    Run cdk diff against the target stack and read the output before anything is deployed. Confirm that the only changes are the new agent container, its environment, the secret permission for the execution role and any updated task definition revision. Check that no resource replacement is planned for the load balancer, database or cluster, and that the API key does not appear as plain text in the output. You are done when the diff matches the intended change and a second engineer has reviewed it.

  6. Deploy the stack with CDK

    Run cdk deploy for the Medplum stack in a maintenance window your team has agreed on, or in a non-production environment first. Watch the CloudFormation events and the ECS service deployment until new tasks reach a steady state and old tasks drain. If the deployment fails, use the CloudFormation rollback and review the stack events before retrying. You are done when the ECS service reports the new task definition as running and the Medplum health check passes on the load balancer.

  7. Verify metrics arrive in Datadog

    In Datadog, open the infrastructure or container view and filter for the Medplum cluster, service and task family. Confirm that container metrics appear with recent timestamps for both the Medplum server and the Datadog agent containers. Also check the agent status output in the task logs for a successful connection to your Datadog site. You are done when metrics from the Medplum tasks show current data in Datadog and the agent logs report no authentication errors.

Storing the Datadog API key without exposing it

The Datadog API key should never sit as a plain value in CDK source. Anyone who can read the repository, a CI log, a synthesized CloudFormation template or the ECS console's task definition view could copy it. Datadog keys grant the ability to submit data to your account, and a leaked key is hard to trace after the fact. Because the Medplum deployment already expresses the Datadog sidecar through the additionalContainers setting, the key must enter that configuration as a reference to a secret store, not as a literal string in the DD_API_KEY environment variable. Confirm in the Medplum deployment code which secret name and key the stack expects, and whether that value is read at synthesis time or at container start. Those two behaviors have different exposure risks.

Reference the secret from the task definition so that ECS injects it into the agent container at launch. The execution role, which ECS uses to pull images and fetch secrets, needs read access only to that one secret ARN. Do not attach a broad policy such as read on all secrets in the account. Review the role's policy in the CDK output and confirm that the agent's task role, which runs the application, has no Datadog secret permission at all, since the application does not need the key. Plan rotation before go-live: create a new key in Datadog, update the secret value, redeploy or restart the service so new tasks pick it up, then revoke the old key. Record who owns each step, because rotation done only in the console tends to drift from the CDK code.

Finally, check that the key does not appear in logs. Container definitions can echo environment values during debugging, and some agent startup output prints configuration. Search the CloudWatch log group for the agent container after a test deployment, and confirm that secret fields are not written there. Ask your Datadog administrator whether the key is a standard API key or whether a scoped key is available for metrics submission only, and use the narrowest key your organization allows. Keep the secret's resource policy and any audit trail from your secret manager as evidence for your security review.

Security and operational considerations for the agent

The Datadog agent runs beside Medplum in the same task, so it inherits the same network path, IAM roles and deploy pipeline. The cards below cover the controls to review before the sidecar reaches production and the signals to watch once it is running.

API key scope and rotation

The DD_API_KEY value lets anyone holding it submit metrics and logs to your Datadog organization. Create a dedicated key for this Medplum environment, not a key shared with other services, and record which team owns it. Confirm in your Datadog account how keys are revoked and rotated, and plan the rotation so the new key is stored in Secrets Manager before the old one is retired. A leaked key cannot be detected by the agent itself, so review key usage in Datadog after rotation.

Medplum Datadog docs

IAM permissions on task and execution roles

The execution role pulls the agent image and reads the secret, while the task role is what the running containers use. Keep the agent's secret read scoped to the single Datadog key ARN rather than a wildcard on Secrets Manager. Check that the task role does not gain permissions for the agent that the Medplum server does not need. Review both roles in the cdk diff output because they are easy to widen by accident.

Network egress from private subnets

Medplum tasks usually run in private subnets, so the agent needs a route to Datadog's intake endpoints for the site set in DD_SITE. Confirm whether egress goes through a NAT gateway, a proxy or a VPC endpoint, and that your firewall or security group rules allow the required outbound HTTPS traffic. Test the path from a running task before you rely on dashboards. Do not open broad outbound access to make the agent work.

Container metadata access

Setting ECS_FARGATE lets the agent read task and container metadata so metrics are tagged by task, container and service. This is read-only access to the ECS task metadata endpoint, but it reveals container names, image tags and task identifiers to anyone who can send data to your Datadog account. Review which Datadog users can see these tags, and avoid placing secrets or patient identifiers in container names or environment variables.

Change control through cdk diff review

Adding the sidecar changes the task definition, so it should go through the same review as other Medplum infrastructure changes. Run cdk diff and check that only the additionalContainers entry, its environment and the secret reference changed. Confirm that the Datadog image tag is pinned to a version your team has tested, and that the diff shows the expected new task revision before deployment.

Resource footprint and post-deploy checks

The sidecar uses CPU and memory from the same Fargate task as the Medplum server, so the task size may need review. After deploy, compare CPU and memory utilization, task restarts and response times against the pre-change baseline for a full business cycle. Watch for the agent container failing health checks or restarting, because a crashing sidecar can stop the task in some configurations. Set an alert on the agent's own status before you consider the rollout complete.

How metrics flow from the Medplum task to Datadog

Metrics start in the Medplum server container and the ECS Fargate task that runs it. The Datadog agent container in the same task collects them and sends them out through the task's egress path in the private subnet to Datadog's intake. The API key reaches the agent from the secret store, not from the CDK code or the image. Check that the agent's outbound route works and that the key never appears in the template or the logs.

Metrics and the API key path from the Medplum task to Datadog.

Questions buyers ask before adding Datadog to Medplum

What does adding Datadog to Medplum cost, and who gets paid for what?

Your costs fall into two groups. Datadog bills you separately for its subscription and usage, and Medplum's documentation does not price that, so confirm the rate with Datadog and your account team. The engineering work to add the sidecar is a separate line: your own engineers' time, or a partner's fixed-scope fee agreed in writing before work starts. The setup itself is largely one-time. Ongoing costs recur through Datadog usage, which grows with the number of containers, hosts and custom metrics you send. Ask any partner for a quote that lists the CDK changes, validation steps, documentation handover and a retest after your next Medplum upgrade as separate line items.

How long does a Datadog sidecar change take to validate?

The answer depends mostly on your CDK pipeline, not on the Datadog configuration itself. A team with a tested non-production stack, automated synth and diff checks, and a repeatable deploy can validate the change in a single cycle. A team that deploys manually, lacks a staging environment, or needs change approval for each stack update will spend more time on review and rollback planning. Confirm how your pipeline previews infrastructure changes, how long your change windows are, and whether a new task definition can be rolled out without downtime on your service. Those three facts set the timeline more than the sidecar does.

What does our internal team need to provide for this work?

Three things should be in place before anyone edits the stack. First, AWS account access with rights to view and deploy the Medplum CDK stack, including ECS, IAM and Secrets Manager resources. Second, Datadog admin access so you can create or read an API key and confirm the site your organization uses. Third, clear ownership of the CDK code, meaning a named team that reviews and merges changes to the Medplum configuration. Without that third item, a sidecar change tends to stall after the first deploy. Your partner will also need a non-production environment or a plan to test in production safely.

Can our own team add Datadog to Medplum without outside help?

Yes, if your team already owns the CDK deployment and works with ECS Fargate. The change centers on the additionalContainers setting in the Medplum CDK configuration, plus the required environment variables for the Datadog site, the API key and Fargate support. The harder parts are usually operational: storing the API key outside source control, confirming the agent starts beside the Medplum containers, and checking that metrics appear in Datadog under the right service tags. If nobody on the team has deployed this stack before, a short fixed-scope review is often cheaper than learning the failure modes during an incident. Check the Medplum Datadog integration documentation before you start.

What changes when we upgrade Medplum, and does the sidecar survive it?

Medplum ships minor versions two to three times a year and patch versions weekly, and each upgrade must go through every minor version in sequence. An upgrade can change the CDK configuration, the container images or the task definition, so treat the Datadog sidecar as part of the deployment and re-check it after each change. Confirm that the additionalContainers block still matches the Medplum version you run, that the API key secret is still referenced correctly, and that metrics still arrive. Build this check into your upgrade runbook rather than discovering a gap weeks later. The Medplum upgrading guide describes the sequence that should be followed.

Where should the Datadog API key live, and how do we keep it out of the code?

Store the API key in AWS Secrets Manager or another secret store your ECS task can read at launch, and reference it from the task definition rather than pasting it into CDK code, environment files or pipeline logs. Limit the IAM role to read only that secret, rotate the key on a schedule, and check that it does not appear in CloudFormation outputs or container logs. Ask your reviewer to confirm that the value is never printed during synth or deploy. These controls matter for regulated Medplum deployments, where an exposed credential becomes an audit finding.

When should we bring in a partner for Datadog on Medplum?

Bring in a partner when the work touches more than the sidecar itself, or when your team lacks time to validate it safely. Typical triggers include no staging environment, a regulated change process that needs documented evidence, a Medplum upgrade planned in the same window, or a monitoring plan that must also cover PostgreSQL, Redis and load balancer metrics. DeployOpen plans, implements, documents and supports self-hosted platforms in your own AWS account, and most engagements are fixed-scope with the scope, deliverables and timeline agreed in writing before work starts. Ask for a written scope that names what is delivered, who runs the Datadog account and how the work is retested after upgrades.

How DeployOpen scopes and delivers Datadog monitoring for Medplum

DeployOpen approaches Datadog on a self-hosted Medplum as a fixed-scope piece of work inside your own AWS account. We agree in writing which services, containers and environments get the agent, then add the sidecar through the CDK stack, verify that container metrics arrive in Datadog, and document how the team operates it afterward.

How we scope

  • Confirm which Medplum ECS Fargate services and environments will receive the Datadog agent sidecar
  • Record the AWS account, region, CDK stack names and the Datadog site your organization uses
  • Agree who owns the Datadog account, the API key and the secret store before any change starts
  • Set out in writing what the engagement covers and what your team provides

How we build

  • Add the agent through the additionalContainers property in your CDK configuration
  • Set DD_SITE, DD_API_KEY and ECS_FARGATE on the agent container as the integration requires
  • Load the API key from a secrets store rather than writing it into source control or the template
  • Apply the change with CDK and review the CloudFormation changeset before deployment

How we hand over

  • Document the CDK diff, environment variables and secret references used in each environment
  • Provide a verification checklist showing where container metrics should appear in Datadog
  • Record how to rotate the API key and roll back the stack change if the agent fails
  • Walk your platform and on-call engineers through the configuration and its ownership

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer
  • Review agent version changes and Medplum upgrades that could affect the sidecar configuration
  • Retest the monitoring setup after infrastructure changes to the ECS task definitions
  • Confirm with your Datadog administrators any changes to the account, site or API key policy

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.