Create an Infrastructure From a Python Object

Create a Custom Infrastructure

If you want to create a custom infrastructure from a Python object, import one of the following infrastructures then specify the arguments:

from prefect.infrastructure import Process

inf = Process(
    name="dev",
    env={"SOME_IMPORTANT_CONFIG": "true"},
)
inf.save("myinf")

To use the new infrastructure, use load():

from my_project.flows import my_flow
from prefect.deployments import Deployment
from prefect.infrastructure.process import Process

infrastructure = Process.load("dev") # load a pre-defined block

deployment = Deployment.build_from_flow(
    flow=my_flow,
    name="test",
    work_queue_name="dev",
    infrastructure=infrastructure
)

deployment.apply() 

Override the Default Arguments

You can also use infra_overrides to override the default arguments:

from my_project.flows import my_flow
from prefect.deployments import Deployment

deployment = Deployment.build_from_flow(
    flow=my_flow,
    name="test",
    work_queue_name="dev",
    infra_overrides=["env.SOME_IMPORTANT_CONFIG=false"],
)

deployment.apply() 
1 Like