azure-event-grid
Azure Event Grid Skill
Build event-driven architectures with Azure Event Grid for reliable event routing.
Triggers
Use this skill when you see:
- azure event grid, event grid, event routing
- event subscription, event handler
- system topic, custom topic
- event filtering, dead letter
Instructions
Create Custom Topic
# Create Event Grid topic
az eventgrid topic create \
--name mytopic \
--resource-group mygroup \
--location eastus
# Get topic endpoint and key
az eventgrid topic show \
--name mytopic \
--resource-group mygroup \
--query "endpoint" -o tsv
az eventgrid topic key list \
--name mytopic \
--resource-group mygroup \
--query "key1" -o tsv
Create Event Subscription
# Subscribe to Azure Function
az eventgrid event-subscription create \
--name mysubscription \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myfunc.azurewebsites.net/runtime/webhooks/eventgrid?functionName=EventHandler \
--endpoint-type azurefunction
# Subscribe to webhook
az eventgrid event-subscription create \
--name webhook-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myapi.example.com/webhooks/events \
--endpoint-type webhook
# Subscribe to Storage Queue
az eventgrid event-subscription create \
--name queue-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint /subscriptions/.../storageAccounts/mystorage/queueServices/default/queues/events \
--endpoint-type storagequeue
# Subscribe to Service Bus
az eventgrid event-subscription create \
--name servicebus-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint /subscriptions/.../namespaces/mybus/queues/events \
--endpoint-type servicebusqueue
Event Filtering
# Filter by event type
az eventgrid event-subscription create \
--name filtered-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myfunc.azurewebsites.net/api/handler \
--included-event-types Microsoft.Storage.BlobCreated Microsoft.Storage.BlobDeleted
# Advanced filter - string prefix
az eventgrid event-subscription create \
--name advanced-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myfunc.azurewebsites.net/api/handler \
--advanced-filter data.url StringBeginsWith https://myaccount.blob.core.windows.net/images
# Advanced filter - numeric comparison
az eventgrid event-subscription create \
--name numeric-sub \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myfunc.azurewebsites.net/api/handler \
--advanced-filter data.contentLength NumberGreaterThan 1000000
System Topics
# Create system topic for storage events
az eventgrid system-topic create \
--name storage-events \
--resource-group mygroup \
--source /subscriptions/.../storageAccounts/mystorage \
--topic-type Microsoft.Storage.StorageAccounts \
--location eastus
# Create subscription for system topic
az eventgrid system-topic event-subscription create \
--name blob-created-sub \
--resource-group mygroup \
--system-topic-name storage-events \
--endpoint https://myfunc.azurewebsites.net/api/BlobHandler \
--included-event-types Microsoft.Storage.BlobCreated
Publish Events
Python SDK
from azure.eventgrid import EventGridPublisherClient
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridEvent
import datetime
# Create client
client = EventGridPublisherClient(
endpoint="https://mytopic.eastus-1.eventgrid.azure.net/api/events",
credential=AzureKeyCredential("your-key")
)
# Publish Event Grid schema event
event = EventGridEvent(
subject="myapp/orders/12345",
event_type="Order.Created",
data={
"orderId": "12345",
"customerId": "C001",
"total": 99.99
},
data_version="1.0"
)
client.send([event])
# Publish Cloud Event schema
from azure.eventgrid import CloudEvent
cloud_event = CloudEvent(
type="Order.Created",
source="/myapp/orders",
data={
"orderId": "12345",
"customerId": "C001"
}
)
client.send([cloud_event])
TypeScript SDK
import { EventGridPublisherClient, AzureKeyCredential } from "@azure/eventgrid";
const client = new EventGridPublisherClient(
"https://mytopic.eastus-1.eventgrid.azure.net/api/events",
"EventGrid",
new AzureKeyCredential("your-key")
);
// Publish events
await client.send([
{
eventType: "Order.Created",
subject: "myapp/orders/12345",
dataVersion: "1.0",
data: {
orderId: "12345",
customerId: "C001",
total: 99.99
}
}
]);
Event Handler (Azure Function)
import azure.functions as func
import json
import logging
app = func.FunctionApp()
@app.event_grid_trigger(arg_name="event")
def event_grid_handler(event: func.EventGridEvent):
logging.info(f"Event type: {event.event_type}")
logging.info(f"Subject: {event.subject}")
logging.info(f"Data: {event.get_json()}")
data = event.get_json()
if event.event_type == "Order.Created":
process_new_order(data)
elif event.event_type == "Order.Cancelled":
process_cancellation(data)
// TypeScript Azure Function
import { app, EventGridEvent, InvocationContext } from "@azure/functions";
export async function eventGridHandler(
event: EventGridEvent,
context: InvocationContext
): Promise<void> {
context.log(`Event type: ${event.eventType}`);
context.log(`Subject: ${event.subject}`);
context.log(`Data: ${JSON.stringify(event.data)}`);
switch (event.eventType) {
case "Order.Created":
await processNewOrder(event.data);
break;
case "Order.Cancelled":
await processCancellation(event.data);
break;
}
}
app.eventGrid("eventGridHandler", {
handler: eventGridHandler,
});
Dead-Lettering
# Enable dead-lettering to storage
az eventgrid event-subscription create \
--name mysubscription \
--source-resource-id /subscriptions/.../topics/mytopic \
--endpoint https://myfunc.azurewebsites.net/api/handler \
--deadletter-endpoint /subscriptions/.../storageAccounts/mystorage/blobServices/default/containers/deadletter
# Set retry policy
az eventgrid event-subscription update \
--name mysubscription \
--source-resource-id /subscriptions/.../topics/mytopic \
--max-delivery-attempts 10 \
--event-ttl 1440
Event Domains
# Create event domain for multi-tenant scenarios
az eventgrid domain create \
--name mydomain \
--resource-group mygroup \
--location eastus
# Create domain topic
az eventgrid domain topic create \
--name tenant-001 \
--domain-name mydomain \
--resource-group mygroup
# Subscribe to domain topic
az eventgrid event-subscription create \
--name tenant-sub \
--source-resource-id /subscriptions/.../domains/mydomain/topics/tenant-001 \
--endpoint https://myfunc.azurewebsites.net/api/TenantHandler
Best Practices
- Event Schema: Use CloudEvents schema for portability
- Filtering: Filter at subscription level to reduce noise
- Dead-Letter: Always configure dead-lettering
- Retry Policy: Set appropriate retry and TTL values
- Domains: Use domains for multi-tenant applications
Common Workflows
Event-Driven Processing
- Create Event Grid topic
- Configure event subscriptions with filters
- Implement event handlers (Functions, webhooks)
- Set up dead-lettering for failed events
- Monitor with Event Grid metrics
React to Azure Events
- Create system topic for Azure resource
- Subscribe to specific event types
- Implement handler function
- Process events and trigger workflows
- Configure alerts for delivery failures
More from housegarofalo/claude-code-base
mqtt-iot
Configure MQTT brokers (Mosquitto, EMQX) for IoT messaging, device communication, and smart home integration. Manage topics, QoS levels, authentication, and bridging. Use when setting up IoT messaging, smart home communication, or device-to-cloud connectivity. (project)
22devops-engineer-agent
Infrastructure and DevOps specialist. Manages Docker, Kubernetes, CI/CD pipelines, and cloud deployments. Expert in GitHub Actions, Azure DevOps, Terraform, and container orchestration. Use for deployment automation, infrastructure setup, or CI/CD optimization.
6postgresql
Design, optimize, and manage PostgreSQL databases. Covers indexing, pgvector for AI embeddings, JSON operations, full-text search, and query optimization. Use when working with PostgreSQL, database design, or building data-intensive applications.
6home-assistant
Ultimate Home Assistant skill - complete administration, wireless protocols (Zigbee/ZHA/Z2M, Z-Wave JS, Thread, Matter), ESPHome device building, advanced troubleshooting, performance optimization, security hardening, custom integration development, and professional dashboard design. Covers configuration, REST API, automation debugging, database optimization, SSL/TLS, Jinja2 templating, and HACS custom cards. Use for any HA task.
6testing
Comprehensive testing skill covering unit, integration, and E2E testing with pytest, Jest, Cypress, and Playwright. Use for writing tests, improving coverage, debugging test failures, and setting up testing infrastructure.
5react-typescript
Build modern React applications with TypeScript. Covers React 18+ patterns, hooks, component architecture, state management (Zustand, Redux Toolkit), server components, and best practices. Use for React development, TypeScript integration, component design, and frontend architecture.
5