Romain Lefebvre
07/01/2026, 2:00 PMMarvin
07/01/2026, 2:00 PMMarvin
07/01/2026, 2:02 PMsend-to-nats action. But you can do this indirectly, and the usual pattern is:
Prefect automation → webhook action → small in-cluster HTTP service → publish to NATS
The important part is that self-hosted automations do support webhook actions, so this is definitely feasible.
Relevant docs:
- Automations concepts
- Custom notifications / webhooks
- Custom events
- Prefect events Python API
What’s supported
For self-hosted, automations can do things like:
- send notifications
- run deployments
- change flow-run state
- call webhooks
There is no native NATS integration/action.
Recommended approach
1. Create a small HTTP service in your cluster that accepts a POST
2. That service publishes the payload to your NATS subject
3. Point a Prefect call-webhook automation action at that service
For example, your automation can send JSON like:
json
{
"flow_run_id": "{{ flow_run.id }}",
"flow_name": "{{ flow.name }}",
"state": "{{ flow_run.state.name }}",
"deployment_id": "{{ deployment.id }}",
"event": {{ event | tojson }}
}
And your bridge service can publish that to NATS.
A minimal sketch of the bridge service:
python
from fastapi import FastAPI, Request
import json
import nats
app = FastAPI()
@app.post("/publish")
async def publish(request: Request):
body = await request.json()
nc = await nats.connect("<nats://nats:4222>")
try:
await nc.publish(
"prefect.flow.running_too_long",
json.dumps(body).encode()
)
finally:
await nc.drain()
return {"ok": True}
Then in Prefect, configure a webhook block to call that endpoint.
Example block creation:
python
from prefect.blocks.webhook import Webhook
webhook = Webhook(
url="<http://your-service.your-namespace.svc.cluster.local/publish>",
method="POST"
)
webhook.save("nats-bridge-webhook", overwrite=True)
Then use that block in your automation’s call-webhook action.
Alternative patterns
If you want, you could also:
- trigger a deployment from the automation, and have that flow publish to NATS
- emit custom Prefect events from flows/tasks and build automation logic around those
But for your use case—“flow has been RUNNING too long, publish to cluster bus”—the webhook bridge is probably the cleanest option.
Bottom line
Yes, this is possible in self-hosted Prefect, but not as a direct NATS target. Use a webhook automation action to hit an internal service that republishes to NATS.
If you want, I can help you with either:
- a concrete automation JSON/YAML example for the webhook action, or
- a more production-ready FastAPI bridge service for Kubernetes.