David Martin Calalang
08/18/2025, 9:06 PMdeployment-outputs
.
How do I do this through the work pool configurations (Cloudwatch Logs Options)Marvin
08/18/2025, 9:06 PMMarvin
08/18/2025, 9:09 PM"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "deployment-outputs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "flow-run"
}
}
Notes and gotchas:
- ECS names streams as: {stream-prefix}/{container-name}/{ecs-task-id}. Each flow run (task) produces a new stream automatically—no extra wiring needed.
- Ensure the task execution role on your ECS tasks has:
- logs:CreateLogStream
- logs:PutLogEvents
- If you ever flip “Create log group” on, also logs:CreateLogGroup
- If you prefer editing the base job template instead of the friendly fields, add the logConfiguration above to the containerDefinitions in the task definition.
Docs for deeper reference:
- Prefect AWS ECS guide
- AWS ECS CloudWatch Logs (awslogs)
If you tell me your region and whether you’re on Fargate or EC2-backed ECS, I can sketch the exact base job template snippet you’d drop in. Otherwise, enjoy your orderly pile of log streams.David Martin Calalang
08/18/2025, 9:11 PMCloudWatch Logs Options
Marvin
08/18/2025, 9:11 PMMarvin
08/18/2025, 9:12 PM{
"awslogs-group": "deployment-outputs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "flow-run",
"awslogs-create-group": "false"
}
Notes:
- Replace us-east-1
with your cluster’s region.
- awslogs-create-group
is a string; leave it "false"
since your group already exists. Set "true"
if you want ECS to create it.
- ECS will create a new stream per task/run automatically: flow-run/<container-name>/<ecs-task-id>
.
Make sure your task execution role has logs:CreateLogStream
and logs:PutLogEvents
. If you ever set create-group to true, add logs:CreateLogGroup
.
Reference: Prefect AWS ECS guideDavid Martin Calalang
08/18/2025, 9:13 PMflow-run
+ the flow idMarvin
08/18/2025, 9:13 PMMarvin
08/18/2025, 9:14 PM{
"awslogs-group": "deployment-outputs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "flow-run-{{ flow_run.id }}",
"awslogs-create-group": "false"
}
What you’ll see in CloudWatch:
- flow-run-<flow_run_id>/<container-name>/<ecs-task-id>
Notes:
- Replace region accordingly.
- Templating with {{ flow_run.id }} works in the ECS work pool’s job template. In most setups, the “CloudWatch Logs Options” field also passes templates through; if it doesn’t in your UI build, drop the same values into the base job template’s containerDefinitions.logConfiguration.options instead.
- You still can’t eliminate the container-name and task-id segments; that’s how ECS structures streams.
- If you run multiple containers per task, you’ll get multiple streams per run (one per container).
Refs:
- Prefect AWS ECS guide
- AWS: Using the awslogs driver with ECSDavid Martin Calalang
08/19/2025, 2:17 PMMarvin
08/19/2025, 2:17 PMMarvin
08/19/2025, 2:18 PMdeployments:
- name: my-flow
entrypoint: flows/my_flow.py:flow
work_pool:
name: my-ecs-pool
job_variables:
cloudwatch_logs_options:
awslogs-group: deployment-outputs
awslogs-region: us-east-1
awslogs-stream-prefix: "flow-run-{{ flow_run.id }}"
awslogs-create-group: "false"
Notes:
- Replace region accordingly.
- The Jinja {{ flow_run.id }}
gives you per-run prefixes; ECS still appends /<container-name>/<ecs-task-id>
to form the final stream name.
- If your deployment sets a custom task_definition
(or task_definition_arn
), Prefect won’t inject log settings—include the logConfiguration
yourself in that task definition.
- Ensure the task execution role has logs:CreateLogStream
and logs:PutLogEvents
.David Martin Calalang
08/19/2025, 2:20 PMjob_variables
look like this right now before adding cloudwatch, how would I add it in this case...
job_variables: {
image: "{{ build_image.image_name }}:{{ build_image.tag }}",
# Can change for scaling...
cpu: 4096,
memory: 8192
}
Marvin
08/19/2025, 2:20 PMMarvin
08/19/2025, 2:20 PMcloudwatch_logs_options
map to your job_variables
. Inline style to match what you’ve got:
job_variables: {
image: "{{ build_image.image_name }}:{{ build_image.tag }}",
cpu: 4096,
memory: 8192,
cloudwatch_logs_options: {
awslogs-group: "deployment-outputs",
awslogs-region: "us-east-1",
awslogs-stream-prefix: "flow-run-{{ flow_run.id }}",
awslogs-create-group: "false"
}
}
Notes:
- Replace us-east-1
with your region.
- Values are strings (that’s what the awslogs driver expects).
- This yields streams like: flow-run-<flow_run_id>/<container-name>/<ecs-task-id>
per run.
- If your deployment uses a custom `task_definition`/`task_definition_arn`, these options won’t be injected—add a logConfiguration
to that task definition instead.
Refs:
- Prefect AWS ECS guideDavid Martin Calalang
08/19/2025, 2:36 PMconfigure_cloudwatch_log
must be enabled to use `cloudwatch_logs_options``Marvin
08/19/2025, 2:36 PMMarvin
08/19/2025, 2:36 PMconfigure_cloudwatch_logs: true
alongside your `cloudwatch_logs_options`:
job_variables: {
image: "{{ build_image.image_name }}:{{ build_image.tag }}",
cpu: 4096,
memory: 8192,
configure_cloudwatch_logs: true,
cloudwatch_logs_options: {
awslogs-group: "deployment-outputs",
awslogs-region: "us-east-1",
awslogs-stream-prefix: "flow-run-{{ flow_run.id }}",
awslogs-create-group: "false"
}
}
Notes:
- The key is configure_cloudwatch_logs
(plural). That error message is… economical.
- If your deployment supplies a custom `task_definition`/`task_definition_arn`, these options won’t be injected; you must put the logConfiguration
directly in that task definition.
- Ensure the task execution role has logs:CreateLogStream
and logs:PutLogEvents
.
Ref: Prefect AWS ECS guideDavid Martin Calalang
08/19/2025, 2:40 PM{{ flow_run.id }}
I want to use my deployment nameMarvin
08/19/2025, 2:41 PMMarvin
08/19/2025, 2:41 PMjob_variables: {
image: "{{ build_image.image_name }}:{{ build_image.tag }}",
cpu: 4096,
memory: 8192,
configure_cloudwatch_logs: true,
cloudwatch_logs_options: {
awslogs-group: "deployment-outputs",
awslogs-region: "us-east-1",
awslogs-stream-prefix: "flow-{{ deployment.name | replace(' ', '-') | replace('/', '-') }}",
awslogs-create-group: "false"
}
}
What you’ll get per run:
- flow-<deployment-name>/<container-name>/<ecs-task-id>
Notes:
- Replace region accordingly.
- I replace spaces and slashes to keep the prefix tidy; optional, but it avoids odd path segments.
- If you’re injecting your own task_definition(_arn), you must put the equivalent logConfiguration there instead.
Ref: Prefect AWS ECS guideDavid Martin Calalang
08/19/2025, 2:48 PMMarvin
08/19/2025, 2:48 PMMarvin
08/19/2025, 2:49 PMtask_definition_arn
), so Prefect isn’t injecting the CloudWatch settings. In that case, you must put the log configuration directly into the ECS task definition.
Here’s the container definition fragment you need in your task definition:
"containerDefinitions": [
{
"name": "prefect",
"image": "<http://123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage:tag|123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage:tag>",
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "deployment-outputs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "flow-my-deployment",
"awslogs-create-group": "false"
}
}
}
]
And a fuller Fargate-style task definition example:
{
"family": "my-prefect-task",
"networkMode": "awsvpc",
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "4096",
"memory": "8192",
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"taskRoleArn": "arn:aws:iam::123456789012:role/prefect-task-role",
"containerDefinitions": [
{
"name": "prefect",
"image": "<http://123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage:tag|123456789012.dkr.ecr.us-east-1.amazonaws.com/myimage:tag>",
"essential": true,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "deployment-outputs",
"awslogs-region": "us-east-1",
"awslogs-stream-prefix": "flow-my-deployment",
"awslogs-create-group": "false"
}
}
}
]
}
Key points:
- ECS will create a new log stream per task automatically at:
flow-my-deployment/<container-name>/<ecs-task-id>
- Dynamic templating (e.g., {{ deployment.name }}
) will NOT work inside a static task definition ARN. If you need per-deployment or per-run prefixes, don’t use a fixed `task_definition_arn`; let Prefect register the task definition and set:
- configure_cloudwatch_logs: true
- cloudwatch_logs_options.awslogs-stream-prefix: "flow-{{ deployment.name }}"
(or similar)
- If you must keep a fixed ARN, choose a static prefix (e.g., flow-my-deployment
) and accept ECS’s container/task-id suffix.
Sanity checks if logs still don’t show:
- In Prefect UI, open the flow run -> Infrastructure tab. If it says it’s using a task_definition_arn
, Prefect didn’t inject logs.
- In the ECS console, open the running task -> Containers. If there’s no “View logs” link, logConfiguration
is missing.
- Ensure the task execution role has logs:CreateLogStream
and logs:PutLogEvents
(and logs:CreateLogGroup
only if you use create-group true).
- Region must match your cluster and log group region.
- Container name used by Prefect should match the one you configured logs for (default is often `prefect`; if yours differs, set the worker/deployment container_name
accordingly).
Docs:
- Prefect AWS ECS guide
- AWS ECS: Using the awslogs log driver