<@ULVA73B9P> Hi, in prefect how can i create a aut...
# ask-marvin
b
@Marvin Hi, in prefect how can i create a automation: if a flow-run from my deployment (A) is Completed, run deployment B. Give me a json and yaml config. Thanks
m
thought for 1281.6 seconds
Great question — you can do this with a Prefect 3.x Automation that listens for the “flow run completed” event from Deployment A and runs Deployment B. Notes: - You’ll need the deployment IDs for A and B. You can get them with:
Copy code
prefect deployment ls
- The CLI does not currently support creating automations, so create this via the Prefect Cloud UI (Automations) or the Automations API. Docs: Event triggers concept JSON (replace the placeholders):
Copy code
{
  "name": "Run B when A completes",
  "description": "When deployment A completes successfully, run deployment B.",
  "enabled": true,
  "triggers": [
    {
      "type": "event",
      "match": {
        "all": [
          {
            "event": "prefect.flow-run.Completed"
          }
        ]
      },
      "match_related": {
        "any": [
          {
            "resource": "prefect.deployment.DEPLOYMENT_A_UUID"
          }
        ]
      }
    }
  ],
  "actions": [
    {
      "type": "run-deployment",
      "deployment_id": "DEPLOYMENT_B_UUID",
      "parameters": {},
      "job_variables": {}
    }
  ]
}
YAML (same fields, different format):
Copy code
name: Run B when A completes
description: When deployment A completes successfully, run deployment B.
enabled: true
triggers:
  - type: event
    match:
      all:
        - event: prefect.flow-run.Completed
    match_related:
      any:
        - resource: prefect.deployment.DEPLOYMENT_A_UUID
actions:
  - type: run-deployment
    deployment_id: DEPLOYMENT_B_UUID
    parameters: {}
    job_variables: {}
Would you like me to fill these in if you share the names/IDs of Deployment A and B?
b
@Marvin in actions, type run_deployment, can i put the deployment name, don’t use deployment_id, it make more automated?
m
thought for 67.8 seconds
Short answer: not today. In Prefect 3.x Automations, the RunDeployment action expects a
deployment_id
(UUID). It does not accept a deployment name/slug. Why this is okay: - Deployment IDs are stable. Updating code or schedules doesn’t change the ID; it only changes if you delete and recreate the deployment. Workarounds if you really want to drive by name: - Use a small webhook you control: have the automation call your webhook (via
CallWebhook
), your service resolves the name → ID using Prefect’s API, then calls the Prefect “create flow run for deployment” endpoint. Helpful API docs: - Read deployment by name - Create flow run from deployment - Or, just look up the ID once and keep using it; it’s usually the simplest. If you want, share the names of Deployment A and B and I’ll grab their IDs and drop in a ready-to-use JSON/YAML automation for you. You can also get them yourself with:
Copy code
prefect deployment ls
# or, for details including ID
prefect deployment inspect "flow-name/deployment-name"