<@ULVA73B9P> using prefect cloud, how do i trigger...
# ask-marvin
s
@Marvin using prefect cloud, how do i trigger a deployment run in response to a prefect webhook call from an external service?
m
thought for 352.3 seconds
Short answer: use a Prefect Cloud Webhook to emit an event, then an Automation with a “Run deployment” action to start your deployment when that event arrives. Here’s the step-by-step in Prefect Cloud (3.x): 1) Create a Cloud Webhook - In the UI: Prefect Cloud → Webhooks → Create webhook. Give it a name and a Jinja template that turns the incoming request into a Prefect event. - Minimal template (static event + resource id):
Copy code
{
  "event": "external.webhook",
  "resource": {
    "prefect.resource.id": "webhook.my-service"
  }
}
- You can also extract fields from the request body/headers using Jinja and include them in your event (for later parameter mapping). For example:
Copy code
{
  "event": "external.webhook",
  "resource": {
    "prefect.resource.id": "webhook.my-service"
  },
  "payload": {
    "customer_id": "{{ body.customer_id | default('') }}",
    "action": "{{ body.action | default('') }}"
  }
}
- CLI alternative (optional):
Copy code
prefect cloud webhook create my-service-hook \
  --description "Triggers deployment from external service" \
  --template '{"event":"external.webhook","resource":{"prefect.resource.id":"webhook.my-service"}}'
- Docs: - Webhooks concept - Create a webhook (how-to) - CLI ref: prefect cloud webhook 2) Create an Automation to run your deployment - In the UI: Automations → Create Automation → Trigger type: “Event” - Match conditions (example): - event equals
external.webhook
- resource.prefect.resource.id equals
webhook.my-service
- Action: “Run deployment” - Select your deployment - Optional: map webhook data to deployment parameters with a Jinja template. If you included a
payload
in the webhook event:
Copy code
{
  "customer_id": "{{ event.payload.customer_id }}",
  "action": "{{ event.payload.action }}"
}
- Docs: - Event triggers - Automations that run deployments 3) Point your external service to the webhook URL - After you create the webhook, copy its URL from the webhook detail page. - Send HTTP requests from your service. Example:
Copy code
curl -X POST <https://api.prefect.cloud/hooks/<your-webhook-id>> \
  -H 'Content-Type: application/json' \
  -d '{"customer_id":"123","action":"created"}'
- On success, the endpoint returns 204 No Content. You can monitor incoming events and any template errors in the Event Feed. Security notes - The webhook URL is an opaque, secret URL—treat it like a token. Rotate it if exposed:
Copy code
prefect cloud webhook rotate <webhook-id>
- Authorization headers from the incoming request are stripped by Prefect for safety. If you need verification, use a hard-to-guess URL and/or include a shared secret in the payload and check for it in your Automation’s filters or parameter template logic. Rotate the URL if compromised. Useful CLI commands
Copy code
prefect cloud webhook ls
prefect cloud webhook get <webhook-id>
prefect cloud webhook update <webhook-id> --template '<new-template>'
prefect cloud webhook toggle <webhook-id>
prefect cloud webhook delete <webhook-id>
Would you like a concrete example for a specific external service (e.g., GitHub, Stripe, Slack) and parameter mapping for your deployment?
s
@Marvin i don’t see Event as one of the trigger types in the drop down
m
thought for 182.5 seconds
Got it — a couple things could explain that. Quick checks: - Are you in a Prefect Cloud 3.x workspace? In 3.x you should see “Webhooks” and “Automations” in the left nav. If you’re in a 2.x workspace, the trigger types are different. If you’re not sure, look for the “3” badge in the workspace switcher or the “Webhooks” page in the nav. - Do you have the Developer role (or higher) in the workspace? Viewers/Runners can’t create automations, and the UI may hide options. - Roles: Manage users and roles Where to find it (Cloud 3.x): - Go to Automations → New automation - The trigger type list should include “Event”, “Metric”, “Compound”, “Sequence” - If the list still doesn’t show “Event”, click the “Advanced” or “JSON” view and set the trigger type explicitly to
event
Minimal JSON you can paste in the Advanced/JSON editor to prove it out:
Copy code
{
  "name": "Run deployment on webhook",
  "enabled": true,
  "trigger": {
    "type": "event",
    "match": {
      "prefect.resource.id": "webhook.my-service"
    },
    "expect": [
      "external.webhook"
    ]
  },
  "actions": [
    {
      "type": "run-deployment",
      "deployment_id": "<your-deployment-id>",
      "parameters": {
        "customer_id": "{{ event.payload.customer_id | default('') }}"
      }
    }
  ]
}
Related docs: - Event triggers: Event triggers - Creating automations: Creating automations - Webhooks: Webhooks concept and Create a webhook If you can share: - A screenshot or list of the trigger types you do see - Whether your workspace is 2.x or 3.x, and your role …I can pinpoint the next step (or provide a ready-to-paste JSON tailored to your setup).