<@ULVA73B9P> Can a successful deployment in one wo...
# ask-marvin
c
@Marvin Can a successful deployment in one workspace trigger the run of a deployment in another workspace?
m
thought for 365.4 seconds
Short answer: not directly. In Prefect 3.x, workspaces are isolated; an automation in Workspace A cannot natively RunDeployment in Workspace B. Automations, webhooks, and events are all workspace-scoped. That said, there are supported patterns to “bridge” workspaces: - Call the Prefect API for Workspace B from Workspace A - In Workspace A, create an Automation that triggers on the success event of your source deployment (e.g.,
prefect.flow-run.Completed
). - Use a CallWebhook action to POST to Workspace B’s API endpoint to create a flow run for the target deployment: - POST https://api.prefect.cloud/api/accounts/&lt;account_id_b&gt;/workspaces/&lt;workspace_id_b&gt;/deployments/&lt;deployment_id_b&gt;/flow-runs - Include header
Authorization: Bearer <API_KEY_WITH_ACCESS_TO_WS_B>
- Body can pass parameters/job variables; you can Jinja-template data from the triggering event. - Docs: - Event triggers and automations - Chaining deployments with events - REST: Create flow run from deployment - Service accounts (grant a service account access to Workspace B and use its API key) - Use the Python SDK against Workspace B - From any environment (including a small serverless function invoked by a CallWebhook), use a client pointed at Workspace B to trigger the target deployment:
Copy code
import os, asyncio
    from prefect.client.orchestration import PrefectClient

    async def main():
        client = PrefectClient(
            api="<https://api.prefect.cloud/api/accounts/<account_id_b>/workspaces/<workspace_id_b>>",
            api_key=os.environ["PREFECT_API_KEY_WS_B"],
        )
        await client.create_flow_run_from_deployment(
            deployment_id="<deployment_id_b>",
            parameters={"upstream_run_id": "<insert if you want to pass context>"},
        )

    asyncio.run(main())
- Docs: Connect to Cloud, Create flow run from deployment - Use the CLI pointed at Workspace B (from CI or a webhook handler) - Run with Workspace B’s API URL and key:
Copy code
export PREFECT_API_URL="<https://api.prefect.cloud/api/accounts/<account_id_b>/workspaces/<workspace_id_b>>"
    export PREFECT_API_KEY="<api_key_with_access_to_ws_b>"

    prefect deployment run "<FLOW_NAME>/<DEPLOYMENT_NAME>"
- This works well from GitHub Actions or your own CI that is triggered after the source deployment completes. Notes and limitations - RunDeployment action only targets deployments within the same workspace; it cannot cross workspaces directly. - Events and webhooks are workspace-scoped; Workspace B cannot “listen” to events from Workspace A without an external bridge (e.g., CallWebhook to an endpoint that calls B’s API). - Prefer using a service account with access to Workspace B to avoid tying auth to a personal key. Would you like an example Automation JSON that uses CallWebhook in Workspace A to trigger a specific deployment in Workspace B? Also, are both workspaces under the same Prefect Cloud account? That determines whether a single service account can span both.