Tim Olshansky
07/15/2025, 10:00 PM21:44:01.401 | INFO | Flow run 'shrewd-turkey' - Downloading flow code from storage at '.' to 21:44:01.401 | INFO | Flow run 'shrewd-turkey' (06876ca3-9c3d-7520-8000-09cbe7a46f8c) - Downloading flow code from storage at '.' or equivalent
3. Manage the tags for a flow run for the AWS ECS Task using prefect specific values (i.e. can we manually add the values we're interested in)
Any one of these things would make our debugging workflows much easier 🙂 Does anyone have any ideas on how we could expose this info?Tim Olshansky
07/15/2025, 10:04 PMMarvin
07/15/2025, 10:04 PMMarvin
07/15/2025, 10:04 PMMarvin
07/15/2025, 10:04 PMMarvin
07/15/2025, 10:04 PMTim Olshansky
07/15/2025, 10:05 PM21:44:01.401 | INFO | Flow run 'shrewd-turkey' - Downloading flow code from storage at '.' to 21:44:01.401 | INFO | Flow run 'shrewd-turkey' (06876ca3-9c3d-7520-8000-09cbe7a46f8c) - Downloading flow code from storage at '.' or equivalent
3. Manage the tags for a flow run for the AWS ECS Task using prefect specific values (i.e. can we manually add the values we're interested in)
Any one of these things would make our debugging workflows much easier 🙂 Do you have any ideas on how we could expose this info?Marvin
07/15/2025, 10:05 PMMarvin
07/15/2025, 10:06 PMpython
from prefect.infrastructure.container import Container
container = Container(
env={
"PREFECT__FLOW_RUN_ID": "${flow_run.id}",
"PREFECT__FLOW_RUN_NAME": "${flow_run.name}"
}
)
2. Including Flow Run ID in Logs:
You can create a custom logger configuration that includes the flow run ID. Here's an example:
python
from prefect import flow
import logging
from prefect.runtime import flow_run
@flow
def your_flow():
logger = logging.getLogger("prefect")
flow_id = flow_run.id
flow_name = flow_run.name
# Create a custom log format that includes both name and ID
<http://logger.info|logger.info>(f"Flow run '{flow_name}' ({flow_id}) - Starting execution")
# Your flow logic here
3. Managing Tags for ECS Tasks:
You can access and manipulate tags within your flow, and pass them to your ECS tasks:
python
from prefect import flow
from prefect.runtime import flow_run
@flow
def your_flow():
# Access current tags
current_tags = flow_run.tags
# You can also set environment variables in your ECS task definition
# that include these tags using the Container infrastructure
container = Container(
env={
"FLOW_TAGS": ",".join(flow_run.tags),
"FLOW_RUN_ID": flow_run.id,
"FLOW_RUN_NAME": flow_run.name
}
)
For your ECS work pool configuration, you can include these values in your task definition. Here's a suggestion for your work pool configuration:
python
from prefect.infrastructure import Container
from prefect.worker.ecs import ECSWorker
container_config = {
"env": {
"PREFECT__FLOW_RUN_ID": "${flow_run.id}",
"PREFECT__FLOW_RUN_NAME": "${flow_run.name}",
"PREFECT__FLOW_TAGS": "${flow_run.tags}"
},
"tags": {
"prefect.flow-name": "${flow_run.name}",
"prefect.flow-id": "${flow_run.id}"
}
}
Additional Suggestions:
1. You can use the flow run ID to create a direct link to the flow run in Prefect Cloud using the format: <https://app.prefect.cloud/account/workspace/flow-runs/flow-run/{flow_run_id}>
2. Consider adding these identifiers as ECS task tags, which will make them searchable in the AWS Console
3. You might want to add custom logging handlers that automatically include this information in all log messages
Would you like me to elaborate on any of these solutions or provide more specific examples for your use case? Also, if you're interested in a particular aspect (like the ECS task definition specifics or logging configuration), I can dive deeper into that area.Tim Olshansky
07/15/2025, 10:08 PMMarvin
07/15/2025, 10:08 PMMarvin
07/15/2025, 10:09 PMbash
prefect work-pool preview "your-pool-name" > ecs-pool-config.json
2. Modify the JSON configuration to include tags. Here's an example configuration that includes both static and dynamic tags:
json
{
"job_configuration": {
"tags": {
"prefect:flow-name": "${flow_run.name}",
"prefect:flow-id": "${flow_run.id}",
"prefect:deployment-id": "${deployment.id}",
"prefect:flow-tags": "${flow_run.tags}",
"environment": "production" // static tag example
}
}
}
3. Update your work pool with the new configuration:
bash
prefect work-pool create "your-pool-name" --type ecs:push --base-job-template ecs-pool-config.json --overwrite
A few important notes about ECS task tagging:
1. AWS has some restrictions on tags:
- Maximum of 50 tags per resource
- Tag keys and values are case-sensitive
- Maximum key length is 128 Unicode characters
- Maximum value length is 256 Unicode characters
- Allowed characters: letters, numbers, spaces, and these special characters: + - = . _ : / @
2. Best practices for tags:
- Use a consistent prefix (like prefect:) to easily identify Prefect-related tags
- Consider which tags will be most useful for filtering in the AWS Console
- Remember that tags can impact cost allocation and monitoring
Here's a more complete example of a work pool configuration that includes both tags and the environment variables we discussed earlier:
json
{
"job_configuration": {
"tags": {
"prefect:flow-name": "${flow_run.name}",
"prefect:flow-id": "${flow_run.id}",
"prefect:deployment-id": "${deployment.id}",
"prefect:environment": "production"
},
"env": {
"PREFECT__FLOW_RUN_ID": "${flow_run.id}",
"PREFECT__FLOW_RUN_NAME": "${flow_run.name}",
"PREFECT__DEPLOYMENT_ID": "${deployment.id}"
},
// ... rest of your ECS configuration ...
}
}
Would you like me to:
1. Provide more details about specific tag configurations?
2. Show how to verify the tags are being applied correctly?
3. Explain how to query/filter ECS tasks using these tags in AWS?