Amith M
08/12/2025, 7:44 PMMarvin
08/12/2025, 7:44 PMNate
08/12/2025, 7:46 PMNate
08/12/2025, 7:47 PMMarvin
08/12/2025, 7:51 PMpip install "prefect[gcp]"
# or with uv
uv pip install "prefect[gcp]"
2) Create the Cloud Run work pool
prefect work-pool create my-cloud-run-pool --type cloud-run
Optionally, inspect the default job template to see supported variables (cpu, memory, timeout, region, service_account_name, vpc connector, etc.):
prefect work-pool get-default-base-job-template --type cloud-run
3) Authenticate to GCP for the worker
Use Application Default Credentials on the worker machine. Either:
- Service account key file:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/sa.json
export GOOGLE_CLOUD_PROJECT=<your-project-id>
- Or gcloud
ADC:
gcloud auth application-default login
gcloud config set project <your-project-id>
Ensure the service account has permissions to run Cloud Run Jobs and pull images (e.g. Cloud Run Admin or Developer, Service Account User, Artifact Registry Reader, and the worker’s SA Token Creator if needed).
4) Start the worker
prefect worker start -p my-cloud-run-pool
Keep this running. It will submit your flow runs to Cloud Run Jobs.
5) Deploy a flow to the pool (Python example)
- Build/push an image accessible by Cloud Run (Artifact Registry recommended).
- Set region and service account via job variables.
from prefect import flow
from prefect.docker import DockerImage
@flow
def hello():
print("Hello from Cloud Run")
# Example image in Artifact Registry:
image_ref = "us-central1-docker.pkg.dev/<project>/<repo>/prefect-flows:latest"
# This will build and push the image (build=True, push=True by default)
hello.deploy(
name="hello-cloud-run",
work_pool_name="my-cloud-run-pool",
image=DockerImage(name=image_ref),
job_variables={
"region": "us-central1",
"service_account_name": "prefect-runner@<project>.<http://iam.gserviceaccount.com|iam.gserviceaccount.com>",
# optional tuning:
"cpu": "1",
"memory": "2Gi",
"timeout": 3600,
# if you need VPC:
# "vpc_connector_name": "projects/<project>/locations/us-central1/connectors/<connector>"
},
)
Alternatively, if you prefer CLI deployments from a project, set the work pool and job variables in your project’s deployment config and run:
prefect deploy ./path/to/flow.py:hello -n hello-cloud-run
(Note: in Prefect 3.x, use prefect deploy
and not the removed deployment build
command.)
Helpful commands you can use
- See the default variables for the Cloud Run worker type:
prefect work-pool get-default-base-job-template --type cloud-run
- Inspect your pool:
prefect work-pool inspect my-cloud-run-pool
A few gotchas (you’re welcome)
- The worker machine must have prefect[gcp]
installed; it’s the thing that actually calls Cloud Run.
- Your image must be accessible to Cloud Run (Artifact Registry repo in the same project/region is safest).
- Set region and service account via job_variables
or by editing the pool’s base job template if you want globals.
Want me to tailor this to your exact project/region/registry? Tell me:
- GCP project ID
- Region for Cloud Run Jobs (e.g., us-central1)
- Service account email to run jobs
- Artifact Registry image URL you want to useAmith M
08/12/2025, 7:59 PMMarvin
08/12/2025, 7:59 PMMarvin
08/12/2025, 7:59 PMAmith M
08/12/2025, 8:02 PMNate
08/12/2025, 8:05 PMprefect worker start
and instead you just use the provisioner as i linked earlier to create a "push" work pool where prefect cloud will run the worker on your behalf as needed from Prefect Cloud itself (using creds you stick on the work pool)Amith M
08/12/2025, 8:12 PMAmith M
08/12/2025, 8:12 PMNate
08/12/2025, 8:13 PMAmith M
08/12/2025, 8:14 PMNate
08/12/2025, 8:15 PMprefect worker start
this guide should applyAmith M
08/12/2025, 9:17 PMAmith M
08/12/2025, 9:17 PMMarvin
08/12/2025, 9:18 PMMarvin
08/12/2025, 9:18 PM