Madushan Pathirana
12/10/2025, 5:38 AMMarvin
12/10/2025, 5:39 AMMarvin
12/10/2025, 5:41 AMprefect flow-run ls --state RUNNING --limit 50
2) Cancel it by ID:
prefect flow-run cancel <flow-run-id>
If the state flips to CANCELLING but the run doesn’t actually stop, the process/container may not be responding to the cancellation signal. Since you’re using an ECS EC2 work pool, you can force-stop the underlying ECS task (this will end the flow run):
- AWS Console: find the task for that flow run in your cluster and Stop it
- Or via AWS CLI:
aws ecs stop-task --cluster <cluster-name> --task <task-arn>
If you want, share the subflow run ID (or its URL) and I can help double-check the state and confirm the right target to stop.Madushan Pathirana
12/10/2025, 5:44 AMMarvin
12/10/2025, 5:45 AMMarvin
12/10/2025, 5:50 AMrun_deployment. That will enqueue a separate flow run on your ECS EC2 work pool, so it runs in its own ECS task/container and can be cancelled independently.
High-level steps:
1) Create a deployment for the child flow
- Put the child flow in its own file, e.g. child.py with @flow def child_flow(...): ...
- From your project root, run prefect deploy and select the child entrypoint (./child.py:child_flow), your ECS work pool, and work queue.
- Note: In Prefect 3.x, this replaces the old 2.x “deployment build” flow.
2) Call the child deployment from the parent using run_deployment
- This triggers the child deployment as a separate flow run (and separate ECS task). Use as_subflow=True to link it in the UI as a subflow of the parent.
Async parent flow example:
from prefect import flow
from prefect.deployments import run_deployment
@flow
async def parent_flow():
# Optional: small POC resources; bump later for prod
ecs_job_vars = {
"cpu": "512",
"memory": "1024",
"env": {
# if you use Prefect Variables/Blocks for DB creds, load them in the child
"PREFECT_LOGGING_LEVEL": "INFO",
},
}
# Trigger the child deployment as its own flow run in ECS
child_run = await run_deployment(
name="child-flow/child-deployment", # flow-name/deployment-name
parameters={"some_param": "value"},
as_subflow=True, # links to parent in UI
timeout=0, # return immediately; parent continues
job_variables=ecs_job_vars, # ECS overrides for this run
# work_queue_name="your-queue", # optional override
)
return child_run
Sync parent flow example (blocks until the child finishes unless you set timeout=0):
from prefect import flow
from prefect.deployments import run_deployment
@flow
def parent_flow():
child_run = run_deployment(
name="child-flow/child-deployment",
as_subflow=True,
timeout=0, # return immediately; omit or set >0 to wait
job_variables={"cpu": "512", "memory": "1024"},
)
return child_run
Notes:
- as_subflow=True links the child to the parent in the UI. If you’d rather it run completely independent of the parent (no link), set as_subflow=False.
- timeout=None (default) waits until the child finishes. timeout=0 returns immediately and the child continues in ECS.
- job_variables lets you override ECS resources per run (e.g., cpu, memory, env, image, IAM roles if needed). These merge with your deployment’s defaults. For your POC, start small (e.g., 512 CPU / 1024 MB). For prod, you mentioned ~8GB ("memory": "8192").
Once you do this, the child run is a first-class flow run with its own ECS task, so you can cancel it from the UI or via CLI:
prefect flow-run cancel <child-flow-run-id>
If you’d like, share your child flow’s entrypoint and I can suggest a minimal prefect deploy setup for your ECS EC2 pool.