<@ULVA73B9P> - any examples or docs with a solutio...
# ask-marvin
k
@Marvin - any examples or docs with a solution to firehouse ALL prefect events into AWS cloudwatch as Metrics?
m
thought for 87.0 seconds
Short answer: I’m not seeing an official “send all Prefect events to AWS CloudWatch Metrics” example or a built-in direct exporter. What does exist in Prefect 3.x is enough to build it cleanly: Best options 1. Prefect Automations → Webhook → AWS Lambda/API Gateway → CloudWatch Metrics - Probably the simplest managed pattern - Use a
call-webhook
automation action and transform event payloads into
PutMetricData
2. Event-triggered flow → boto3 CloudWatch - Good if you want Prefect to own the transformation logic 3. Custom event subscriber service - Best if you truly mean all events continuously - Subscribe to Prefect events and forward them to CloudWatch yourself Relevant Prefect docs - Events API/catalog: Prefect events reference - Automations: Automations concepts - Event triggers: Event triggers - Webhooks: Webhooks concepts - Create a webhook: Create a webhook - Pass event payloads to flows: Passing event payloads to flows - Custom notifications / templating examples: Custom notifications A practical caveat If you literally want all Prefect events as CloudWatch metrics, be careful: - CloudWatch custom metrics can get expensive - high-cardinality dimensions like flow run IDs / task run IDs are usually a bad idea - better to aggregate to dimensions like
deployment
,
flow
,
work_pool
,
state
,
event
So usually you’d map: -
prefect.flow-run.Completed
→ metric
FlowRunCompleted
-
prefect.flow-run.Failed
→ metric
FlowRunFailed
-
prefect.task-run.Failed
→ metric
TaskRunFailed
Example architecture
Copy code
text
Prefect Events
  -> Automation trigger
  -> call-webhook
  -> API Gateway / Lambda
  -> CloudWatch PutMetricData
If you want true “all events” streaming A custom subscriber is likely the better fit than many automations. Very rough sketch:
Copy code
python
from prefect.events import get_events_subscriber
import boto3

cloudwatch = boto3.client("cloudwatch")

async def forward_events():
    async with get_events_subscriber() as subscriber:
        async for event in subscriber:
            cloudwatch.put_metric_data(
                Namespace="Prefect",
                MetricData=[
                    {
                        "MetricName": event.event,
                        "Value": 1,
                        "Unit": "Count",
                    }
                ],
            )
That said, I’d normalize metric names before sending them. What I did not find - No official Prefect doc specifically for CloudWatch Metrics export - No obvious built-in “export all events to AWS CloudWatch” feature - No matching GitHub discussion surfaced for this exact pattern If you want, I can give you either: 1. a full Lambda example for
call-webhook
→ CloudWatch, or 2. a full subscriber service example for forwarding all events.