hey <@ULVA73B9P> Iam running my prefect flows by c...
# ask-community
k
hey @Marvin Iam running my prefect flows by creating the deployments on ecs using faragate spot , i see that iam getting my deployment id ,name, flow name and flow run id on my ecs tasks as tags in the aws console, how are they getting generated
m
thought for 507.5 seconds
Great question — that tagging is expected behavior when you run Prefect deployments on ECS via the ECS worker. What’s happening - The Prefect ECS worker constructs the AWS RunTask request for each flow run and automatically includes a set of AWS resource tags to make it easy to correlate ECS tasks with Prefect objects. - Those tags are populated from the flow run and deployment metadata (e.g., deployment id/name, flow name, flow run id) at submission time and attached to the ECS task. Where this comes from - This behavior lives in the ECS worker implementation in the prefect-aws integration: prefect_aws.workers.ecs_worker - ECS guide for Prefect 3.x: ECS guide - Workers and job templates (how these requests are built): Developing a custom worker Can I customize or disable these tags? - Yes — via your ECS work pool’s job template. The worker uses a JSON job template to build the
RunTask
request. In your Prefect UI, open your ECS work pool and edit the “Task run request template.” You can: - Add your own tags - Remove the Prefect-provided tags - Replace values with your own expressions If you’d like, share a screenshot of the “Task run request template” from your ECS work pool and I can point out exactly where to tweak the tags for your setup.
k
@Marvin where can i add here exactly "task_run_request": { "tags": "{{ labels }}", "cluster": "{{ cluster }}", "overrides": { "cpu": "{{ cpu }}", "memory": "{{ memory }}", "taskRoleArn": "{{ task_role_arn }}", "containerOverrides": [ { "cpu": "{{ cpu }}", "name": "{{ container_name }}", "memory": "{{ memory }}", "command": "{{ command }}", "environment": "{{ env }}" } ] }, "launchType": "{{ launch_type }}", "taskDefinition": "{{ task_definition_arn }}", "enableExecuteCommand": true, "capacityProviderStrategy": "{{ capacity_provider_strategy }}" },
m
thought for 78.7 seconds
You add them in your ECS work pool’s job template, inside the task_run_request object. In your snippet, replace the current line
Copy code
"tags": "{{ labels }}",
with a proper AWS Tag list. For example:
Copy code
"task_run_request": {
  "tags": [
    {"key": "env", "value": "{{ env }}"},
    {"key": "owner", "value": "data-platform"},
    {"key": "application", "value": "prefect"}
  ],
  "cluster": "{{ cluster }}",
  "overrides": {
    "cpu": "{{ cpu }}",
    "memory": "{{ memory }}",
    "taskRoleArn": "{{ task_role_arn }}",
    "containerOverrides": [
      {
        "cpu": "{{ cpu }}",
        "name": "{{ container_name }}",
        "memory": "{{ memory }}",
        "command": "{{ command }}",
        "environment": "{{ env }}"
      }
    ]
  },
  "launchType": "{{ launch_type }}",
  "taskDefinition": "{{ task_definition_arn }}",
  "enableExecuteCommand": true,
  "capacityProviderStrategy": "{{ capacity_provider_strategy }}"
}
Notes: - AWS ECS expects tags as a list of objects with
key
and
value
. - Prefect’s ECS worker already adds its own Prefect metadata tags (e.g., flow run/deployment info), so you only need to add your custom tags here; Prefect’s defaults will still be included. - You can reference your job variables (like
{{ env }}
) in tag values, just like you do elsewhere in the template. Where to edit this: - Prefect UI > Work Pools > your ECS pool > Edit “Task run request template”. - Docs for ECS worker and job templates: ECS guide - AWS RunTask API (tag format reference): API_RunTask