Define a flow that accepts payload data
Create a flow that accepts a dictionary payload:Emit a custom event with payload
Emit custom events with structured payloads using the Prefect CLI:Configure the automation trigger
Create a new automation from the Automations page. In the trigger configuration, set it to listen for your custom event. The trigger definition should look like this in theJSON tab:
Configure the action to pass the payload
Add a “Run a deployment” action and configure it to pass the event payload as a dictionary to your flow. In the UI, you’ll need to use “custom JSON” mode for thepayload parameter and enter:
- Renders the Jinja template
{{ event.payload | tojson }}to a JSON string - Automatically parses the JSON string back to a dictionary using the
jsonhandler
dict type rather than a string.
Define everything in Python
You can define the flow and trigger entirely in Python usingDeploymentEventTrigger:
event_payload_example.py
Targeting the deploymentWhen using
DeploymentEventTrigger, events must target the deployment’s resource ID (prefect.deployment.<deployment-id>). You can find the deployment ID in the serve output or with prefect deployment ls.