Public documentation
Documentation indexRead as MarkdownAWS: ECS Fargate behind CloudFront
This recipe connects browser requests through CloudFront and an Application Load Balancer to an instrumented ECS Fargate API. The application exports traces directly to Corridora over HTTPS. CloudFront and ALB do not gain their own spans simply by forwarding the request.
Use the cloud overview for the trace contract and common settings. For EC2, combine the host guide with the same export settings; for EKS, use Kubernetes.
Before deployment
- An existing ECS cluster/service, Fargate networking, ALB target group, and working HTTPS API route.
- An instrumented image that listens on port 8080 and is available to the task execution role. Build the trace-check API, or use the language guides and Docker guide for your application.
- An AWS deployment identity permitted to register task definitions, update the service, and pass the selected IAM roles.
- A task execution role permitted to pull the image and read the selected Secrets Manager secret. Add
secretsmanager:GetSecretValueand, for a customer-managed encryption key, the requiredkms:Decryptpermission. - Task network access to the registry and secret service, plus outbound HTTPS to your Corridora ingest host. Private subnets need a suitable egress path.
Keep application AWS permissions in its task role. Secret injection uses the task execution role; these are different responsibilities.
Store the export header
Create a Secrets Manager plaintext secret containing the complete exporter-header value:
X-CORRIDORA-KEY=YOUR_BACKEND_INGEST_KEY
Copy its ARN for the task definition. Use the secret console or your existing secure deployment workflow; do not commit the secret value into JSON. Updating the secret does not change environment variables inside tasks that are already running. Start new tasks after rotation.
Configure the task
Copy task-definition.json into your deployment workspace. It is a complete minimal single-container Fargate definition, intended for a matching example service. Replace its image URI, role ARN, secret ARN, service identity, and release value.
For an existing application with extra containers, volumes, health checks, resource requirements, logging, or task-role permissions, merge the example's environment and secret entries into your current definition. Preserve the container name and port referenced by the ECS service's load balancer configuration.
The key reference has this shape:
{
"secrets": [
{
"name": "OTEL_EXPORTER_OTLP_HEADERS",
"valueFrom": "arn:aws:secretsmanager:REGION:ACCOUNT:secret:YOUR_SECRET"
}
]
}
The example enables traces and W3C context propagation. It requires instrumentation in the image and does not turn ECS platform logs into OTLP logs.
Register and roll out
Run from the directory containing your reviewed task-definition.json, with AWS CLI credentials for the intended account and region:
export AWS_REGION=us-east-1
export ECS_CLUSTER=YOUR_CLUSTER
export ECS_SERVICE=YOUR_SERVICE
TASK_DEFINITION_ARN=$(aws ecs register-task-definition \
--cli-input-json file://task-definition.json \
--query 'taskDefinition.taskDefinitionArn' --output text)
aws ecs update-service \
--cluster "$ECS_CLUSTER" --service "$ECS_SERVICE" \
--task-definition "$TASK_DEFINITION_ARN"
aws ecs wait services-stable \
--cluster "$ECS_CLUSTER" --services "$ECS_SERVICE"
Use your existing deployment mechanism if the service uses a deployment controller that does not support this update path. A stable ECS service establishes deployment health, not successful telemetry receipt.
Preserve browser context at CloudFront
For the API behavior, select your ALB origin, allow the API methods, and use the managed CachingDisabled cache policy. Allow OPTIONS when the API is cross-origin.
Use an origin request policy that forwards traceparent and the application's authentication, cookies, query strings, and required headers. Managed AllViewer forwards the viewer's Host; AllViewerExceptHostHeader uses the origin's Host instead. Choose according to the ALB routing and TLS configuration. A narrower custom policy must explicitly retain the fields the API uses.
Do not configure a fixed trace header on the origin or add each trace ID to the cache key. Preserve the origin's CORS responses and permit traceparent in API preflights. Install RUM in the frontend; use its exact API origin allowlist for cross-origin requests.
Verify the deployed path
- Confirm the new task revision is running and the container loaded instrumentation.
- Check ECS events for image-pull, secret-access, or startup errors.
- Issue a browser fetch through the CloudFront API route after RUM initializes.
- Confirm the outgoing
traceparentreaches the backend and both spans are visible under the same trace ID in Corridora. - Exercise a downstream request and repeat after a task replacement to check export on termination and startup.
Use deployment verification for the complete acceptance test. If IDs connect at the ALB URL but split at CloudFront, inspect forwarding, cache, and WAF rules. If only AWS-native traces appear, confirm an actual Corridora exporter is configured.
Lambda requires Lambda-aware instrumentation and flushing; the long-running ECS recipe is not a Lambda handler installation. AWS request IDs and X-Amzn-Trace-Id do not replace W3C browser trace context.