This page is about the block-based deployment model. The Work Pools and Workers based deployment model simplifies the specification of a flow's infrastructure and runtime environment. If you have existing agents, you can upgrade from agents to workers to significantly enhance the experience of deploying flows.
We encourage you to check out the new deployment experience with guided command line prompts and convenient CI/CD with prefect.yaml files.
With remote storage blocks, you can package not only your flow code script but also any supporting files, including your custom modules, SQL scripts and any configuration files needed in your project.
To define how your flow execution environment should be configured, you may either reference pre-configured infrastructure blocks or let Prefect create those automatically for you as anonymous blocks (this happens when you specify the infrastructure type using --infra flag during the build process).
Work queue affinity improved starting from Prefect 2.0.5
Until Prefect 2.0.4, tags were used to associate flow runs with work queues. Starting in Prefect 2.0.5, tag-based work queues are deprecated. Instead, work queue names are used to explicitly direct flow runs from deployments into queues.
Note that backward compatibility is maintained and work queues that use tag-based matching can still be created and will continue to work. However, those work queues are now considered legacy and we encourage you to use the new behavior by specifying work queues explicitly on agents and deployments.
Each deployment is associated with a single flow, but any given flow can be referenced by multiple deployments.
Deployments are uniquely identified by the combination of: flow_name/deployment_name.
This enables you to run a single flow with different parameters, based on multiple schedules and triggers, and in different environments. This also enables you to run different versions of the same flow for testing and production purposes.
A deployment definition captures the settings for creating a deployment object on the Prefect API. You can create the deployment definition by:
Run the prefect deployment build CLI command with deployment options to create a deployment.yaml deployment definition file, then run prefect deployment apply to create a deployment on the API using the settings in deployment.yaml.
Define a Deployment Python object, specifying the deployment options as properties of the object, then building and applying the object using methods of Deployment.
The minimum required information to create a deployment includes:
The path and filename of the file containing the flow script.
The name of the entrypoint flow function — this is the flow function that starts the flow and calls and additional tasks or subflows.
The name of the deployment.
You may provide additional settings for the deployment. Any settings you do not explicitly specify are inferred from defaults.
To create a deployment on the CLI, there are two steps:
Build the deployment definition file deployment.yaml. This step includes uploading your flow to its configured remote storage location, if one is specified.
To build the deployment definition file deployment.yaml, run the prefect deployment build Prefect CLI command from the folder containing your flow script and any dependencies of the script.
$prefectdeploymentbuild[OPTIONS]PATH
Path to the flow is specified in the format path-to-script:flow-function-name — The path and filename of the flow script file, a colon, then the name of the entrypoint flow function.
Creates a marvin_flow-deployment.yaml file for your deployment based on your flow code and options.
Uploads your flow files to the configured storage location (local by default).
Submit your deployment to the work queue test. The work queue test will be created if it doesn't exist.
Uploading files may require storage filesystem libraries
Note that the appropriate filesystem library supporting the storage location must be installed prior to building a deployment with a storage block. For example, the AWS S3 Storage block requires the s3fs library.
Ignore files or directories from a deployment
By default, Prefect uploads all files in the current folder to the configured storage location (local by default) when you build a deployment.
If you want to omit certain files or directories from your deployments, add a .prefectignore file to the root directory. .prefectignore enables users to omit certain files or directories from their deployments.
Similar to other .ignore files, the syntax supports pattern matching, so an entry of *.pyc will ensure all .pyc files are ignored by the deployment call when uploading to remote storage.
You may specify additional options to further customize your deployment.
Options
Description
PATH
Path, filename, and flow name of the flow definition. (Required)
--apply, -a
When provided, automatically registers the resulting deployment with the API.
--cron TEXT
A cron string that will be used to set a CronSchedule on the deployment. For example, --cron "*/1 * * * *" to create flow runs from that deployment every minute.
An integer specifying an interval (in seconds) that will be used to set an IntervalSchedule on the deployment. For example, --interval 60 to create flow runs from that deployment every minute.
--name TEXT, -n
The name of the deployment.
--output TEXT, -o
Optional location for the YAML manifest generated as a result of the build step. You can version-control that file, but it's not required since the CLI can generate everything you need to define a deployment.
--override TEXT
One or more optional infrastructure overrides provided as a dot delimited path. For example, specify an environment variable: env.env_key=env_value. For Kubernetes, specify customizations: customizations='[{"op": "add","path": "/spec/template/spec/containers/0/resources/limits", "value": {"memory": "8Gi","cpu": "4000m"}}]' (note the string format).
--param
An optional parameter override, values are parsed as JSON strings. For example, --param question=ultimate --param answer=42.
--params
An optional parameter override in a JSON string format. For example, --params=\'{"question": "ultimate", "answer": 42}\'.
--path
An optional path to specify a subdirectory of remote storage to upload to, or to point to a subdirectory of a locally stored flow.
--pool TEXT, -p
The work pool that will handle this deployment's runs. │
--rrule TEXT
An RRule that will be used to set an RRuleSchedule on the deployment. For example, --rrule 'FREQ=HOURLY;BYDAY=MO,TU,WE,TH,FR;BYHOUR=9,10,11,12,13,14,15,16,17' to create flow runs from that deployment every hour but only during business hours.
--skip-upload
When provided, skips uploading this deployment's files to remote storage.
--storage-block TEXT, -sb
The storage block to use, in block-type/block-name or block-type/block-name/path format. Note that the appropriate library supporting the storage filesystem must be installed.
--tag TEXT, -t
One or more optional tags to apply to the deployment.
--version TEXT, -v
An optional version for the deployment. This could be a git commit hash if you use this command from a CI/CD pipeline.
--work-queue TEXT, -q
The work queue that will handle this deployment's runs. It will be created if it doesn't already exist. Defaults to None. Note that if a work queue is not set, work will not be scheduled.
When specifying a storage block with the -sb or --storage-block flag, you may specify the block by passing its slug. The storage block slug is formatted as block-type/block-name.
For example, s3/example-block is the slug for an S3 block named example-block.
In addition, when passing the storage block slug, you may pass just the block slug or the block slug and a path.
block-type/block-name indicates just the block, including any path included in the block configuration.
block-type/block-name/path indicates a storage path in addition to any path included in the block configuration.
When specifying an infrastructure block with the -ib or --infra-block flag, you specify the block by passing its slug. The infrastructure block slug is formatted as block-type/block-name.
Block name
Block class name
Block type for a slug
Azure
Azure
azure
Docker Container
DockerContainer
docker-container
GitHub
GitHub
github
GCS
GCS
gcs
Kubernetes Job
KubernetesJob
kubernetes-job
Process
Process
process
Remote File System
RemoteFileSystem
remote-file-system
S3
S3
s3
SMB
SMB
smb
GitLab Repository
GitLabRepository
gitlab-repository
Note that the appropriate library supporting the storage filesystem must be installed prior to building a deployment with a storage block. For example, the AWS S3 Storage block requires the s3fs library. See Storage for more information.
A deployment's YAML file configures additional settings needed to create a deployment on the server.
A single flow may have multiple deployments created for it, with different schedules, tags, and so on. A single flow definition may have multiple deployment YAML files referencing it, each specifying different settings. The only requirement is that each deployment must have a unique name.
The default {flow-name}-deployment.yaml filename may be edited as needed with the --output flag to prefect deployment build.
###### A complete description of a Prefect Deployment for flow 'Cat Facts'###name:catfactdescription:nullversion:c0fc95308d8137c50d2da51af138aa23# The work queue that will handle this deployment's runswork_queue_name:testwork_pool_name:nulltags:[]parameters:{}schedule:nullinfra_overrides:{}infrastructure:type:processenv:{}labels:{}name:nullcommand:-python--m-prefect.enginestream_output:true###### DO NOT EDIT BELOW THIS LINE###flow_name:Cat Factsmanifest_path:nullstorage:nullpath:/Users/terry/test/testflows/catfactentrypoint:catfact.py:catfacts_flowparameter_openapi_schema:title:Parameterstype:objectproperties:url:title:urlrequired:-urldefinitions:null
Editing deployment.yaml
Note the big DO NOT EDIT comment in your deployment's YAML: In practice, anything above this block can be freely edited before running prefect deployment apply to create the deployment on the API.
We recommend editing most of these fields from the CLI or Prefect UI for convenience.
You may provide default parameter values in the deployment.yaml configuration, and these parameter values will be used for flow runs based on the deployment.
To configure default parameter values, add them to the parameters: {} line of deployment.yaml as JSON key-value pairs. The parameter list configured in deployment.yamlmust match the parameters expected by the entrypoint flow function.
You can edit default parameters for deployments in the Prefect UI, and you can override default parameter values when creating ad-hoc flow runs via the Prefect UI.
To edit parameters in the Prefect UI, go the the details page for a deployment, then select Edit from the commands menu. If you change parameter values, the new values are used for all future flow runs based on the deployment.
To create an ad-hoc flow run with different parameter values, go the the details page for a deployment, select Run, then select Custom. You will be able to provide custom values for any editable deployment fields. Under Parameters, select Custom. Provide the new values, then select Save. Select Run to begin the flow run with custom values.
If you want the Prefect API to verify the parameter values passed to a flow run against the schema defined by parameter_openapi_schema, set enforce_parameter_schema to true.
When you've configured deployment.yaml for a deployment, you can create the deployment on the API by running the prefect deployment apply Prefect CLI command.
When you run a deployed flow with Prefect, the following happens:
The user runs the deployment, which creates a flow run. (The API creates flow runs automatically for deployments with schedules.)
An agent picks up the flow run from a work queue and uses an infrastructure block to create infrastructure for the run.
The flow run executes within the infrastructure.
Agents and work pools enable the Prefect orchestration engine and API to run deployments in your local execution environments. To execute deployed flow runs you need to configure at least one agent.
Scheduled flow runs
Scheduled flow runs will not be created unless the scheduler is running with either Prefect Cloud or a local Prefect server started with prefect server start.
Scheduled flow runs will not run unless an appropriate agent and work pool are configured.
frommy_project.flowsimportmy_flowfromprefect.deploymentsimportDeploymentfromprefect.filesystemsimportS3storage=S3.load("dev-bucket")# load a pre-defined blockdeployment=Deployment.build_from_flow(flow=my_flow,name="s3-example",version=2,work_queue_name="aws",work_pool_name="default-agent-pool",storage=storage,infra_overrides={"env":{"ENV_VAR":"value"}},)deployment.apply()
If you have settings that you want to share from an existing deployment you can load those settings:
If you specify a schedule for a deployment, the deployment will execute its flow automatically on that schedule as long as a Prefect server and agent are running. Prefect Cloud creates schedules flow runs automatically, and they will run on schedule if an agent is configured to pick up flow runs for the deployment.
deployment triggers are only available in Prefect Cloud
Deployments can optionally take a trigger specification, which will configure an automation to run the deployment based on the presence or absence of events, and optionally pass event data into the deployment run as parameters via jinja templating.
When applied, this deployment will start a flow run upon the completion of the upstream flow specified in the match_related key, with the flow run passed in as a parameter. Triggers can be configured to respond to the presence or absence of arbitrary internal or external events. The trigger system and API are detailed in Automations.
In the Prefect UI, you can click the Run button next to any deployment to execute an ad hoc flow run for that deployment.
The prefect deployment CLI command provides commands for managing and running deployments locally.
Command
Description
apply
Create or update a deployment from a YAML file.
build
Generate a deployment YAML from /path/to/file.py:flow_function.
delete
Delete a deployment.
inspect
View details about a deployment.
ls
View all deployments or deployments for specific flows.
pause-schedule
Pause schedule of a given deployment.
resume-schedule
Resume schedule of a given deployment.
run
Create a flow run for the given flow and deployment.
schedule
Commands for interacting with your deployment's schedules.
set-schedule
Set schedule for a given deployment.
Deprecated Schedule Commands
The pause-schedule, resume-schedule, and set-schedule commands are deprecated due to the introduction of multi-schedule support for deployments. Use the new prefect deployment schedule command for enhanced flexibility and control over your deployment schedules.
You'll need to configure agents and work pools that can create flow runs for deployments in remote environments. PREFECT_API_URL must be set for the environment in which your agent is running.
If you want the agent to communicate with Prefect Cloud from a remote execution environment such as a VM or Docker container, you must configure PREFECT_API_URL in that environment.