Fredrik Hoem Grelland
11/11/2025, 9:11 AMMarvin
11/11/2025, 9:11 AMMarvin
11/11/2025, 9:19 AM.submit(...).
3) The flow code and parameters are serialized and executed on the remote worker. No deployment needed.
Python examples
- Docker work pool
from prefect import flow
from prefect_docker.experimental.decorators import docker
@docker(work_pool="my-docker-pool", image="prefecthq/prefect:3-latest")
@flow
def my_flow(name: str = "world"):
print(f"Hello {name} from Docker!")
if __name__ == "__main__":
fut = my_flow.submit(name="Prefect")
print(f"Submitted flow run: {fut.id}")
state = fut.result() # wait for completion
print(state)
- Kubernetes work pool
from prefect import flow
from prefect_kubernetes.experimental.decorators import kubernetes
@kubernetes(
work_pool="my-k8s-pool",
image="prefecthq/prefect:3-latest",
namespace="prefect"
)
@flow
def my_flow(x: int = 1):
return x + 1
if __name__ == "__main__":
fut = my_flow.submit(x=41)
print(f"Submitted flow run: {fut.id}")
print(fut.result())
- AWS ECS work pool
from prefect import flow
from prefect_aws.experimental.decorators import ecs
@ecs(
work_pool="my-ecs-pool",
image="prefecthq/prefect:3-latest",
cpu="512", memory="1024"
)
@flow
def my_flow():
return "hello from ECS"
if __name__ == "__main__":
print(my_flow.submit().result())
CLI you’ll use around this (to set up the pool/worker)
- Create a work pool:
prefect work-pool create my-docker-pool --type docker
prefect work-pool create my-k8s-pool --type kubernetes
prefect work-pool create my-ecs-pool --type ecs
- Start a worker for the pool (ensure the extra is installed for your infra):
uv run --with 'prefect[docker]' prefect worker start -p my-docker-pool
uv run --with 'prefect[kubernetes]' prefect worker start -p my-k8s-pool
uv run --with 'prefect[aws]' prefect worker start -p my-ecs-pool
Notes and gotchas
- This feature is marked experimental but is widely used.
- Your flow’s imports must be available in the remote runtime image. If you’re not building a custom image, pick an image that already contains your dependencies (e.g., a team base image) or add them to that base.
- Objects passed to the flow must be cloudpickle-serializable; create non-serializable resources (e.g., DB connections) inside the flow.
- You can customize the infra via job variables in the decorator (e.g., image, env vars, namespace, resources).
Would you like me to tailor an example for your exact work pool type (Docker, Kubernetes, ECS) and pool name? If you share those details, I’ll provide a ready-to-run snippet.