<@ULVA73B9P> I need to run a flow on my workpool w...
# ask-marvin
f
@Marvin I need to run a flow on my workpool without creating a docker image and deployment. Can I do that from my local development env. I remember reading about a such feature added some time ago, where I can run a flow, but in remote infra ?
m
thought for 521.9 seconds
Yes — in Prefect 3.x you can do this with Infrastructure-Bound Flows. This lets you submit a flow from your local dev session directly to a remote work pool (Docker, Kubernetes, ECS, etc.) without creating a deployment or building a new image. You just need a running worker on that work pool. Feature/docs: - Infrastructure-Bound Flows (aka “Submit flows directly to dynamic infrastructure”): Docs How it works (quick start): 1) Create a work pool for your target infrastructure and start a worker for it. 2) In your local code, decorate the flow with the infra decorator for that pool and call
.submit(...)
. 3) The flow code and parameters are serialized and executed on the remote worker. No deployment needed. Python examples - Docker work pool
Copy code
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
Copy code
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
Copy code
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:
Copy code
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):
Copy code
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.