Azure Event Grid in Logic Apps

Event-Driven Workflows with Event Grid Triggers


Introduction

Azure Logic Apps can be triggered by events from Azure Event Grid, enabling you to build powerful event-driven workflows that respond to changes in your Azure resources. Whether it's a new file uploaded to blob storage, a VM state change, or custom application events, Logic Apps can process them all through the Event Grid trigger.

This comprehensive guide covers:

  • Event Grid trigger — Setting up the trigger in Logic Apps
  • Event types — Available event types from Azure services
  • Configuration — Webhook vs polling modes
  • Processing events — Extracting and using event data
  • Real-world examples — Complete workflow patterns

Understanding the Trigger

How It Works

┌─────────────────────────────────────────────────────────────────────┐
│                  EVENT GRID TRIGGER FLOW                            │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Azure Resource Change                                             │
│        │                                                            │
│        ▼                                                            │
│   Event Grid Topic ───────────┐                                     │
│                                │                                    │
│        ┌───────────────────────┼───────────────────────┐            │
│        │                       │                       │            │
│        ▼                       ▼                       ▼            │
│   ┌─────────┐           ┌─────────┐           ┌─────────┐           │
│   │ Function│           │ Logic   │           │ Custom  │           │
│   │ Handler │           │   App   │           │   App   │           │
│   └─────────┘           └────┬────┘           └─────────┘           │
│                                │                                    │
│                                ▼                                    │
│   ┌──────────────────────────────────────────────────────────┐      │
│   │              LOGIC APP WORKFLOW                          │      │
│   │                                                          │      │
│   │  [Event Grid Trigger]                                    │      │
│   │       ↓                                                  │      │
│   │  [Parse Event] ─ Extract event data                      │      │
│   │       ↓                                                  │      │
│   │  [Condition] ─ Filter based on event type                │      │
│   │       ↓                                                  │      │
│   │  [Action 1] ─ Process the event                          │      │
│   │       ↓                                                  │      │
│   │  [Action 2] ─ Take action                                │      │
│   └──────────────────────────────────────────────────────────┘      │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Trigger Types

Trigger NameDescriptionUse Case
Event GridGeneric event triggerCustom topics, any event
Azure BlobSpecific blob eventsFile uploads
Azure Data LakeData lake eventsAnalytics triggers
Event HubEvent Hub messagesStream processing

Configure Event Grid Trigger

Step-by-Step Setup

  1. Create Logic App — Standard or Consumption plan
  2. Open Designer — Navigate to Logic App designer
  3. Add Trigger — Search for "Event Grid"
  4. Select Trigger — "When a resource event occurs"

Basic Configuration

Subscription: Azure subscription
Resource Type: Microsoft.Storage.StorageAccounts
Resource Name: my-storage-account
Event Type: Microsoft.Storage.BlobCreated

Advanced Filters

{
  "filter": {
    "subjectBeginsWith": "uploads/",
    "includedEventTypes": [
      "Microsoft.Storage.BlobCreated",
      "Microsoft.Storage.BlobDeleted"
    ]
  }
}

Configuration Parameters

ParameterDescriptionExample
SubscriptionAzure subscriptionPay-as-you-go
Resource GroupResource grouprg-production
Resource TypeAzure resource typeMicrosoft.Storage.StorageAccounts
Resource NameSpecific resourcemystorageaccount
Event TypeEvent to trigger onMicrosoft.Storage.BlobCreated

Webhook vs Polling

Webhook Mode (Push - Recommended)

┌─────────────────────────────────────────────────────────────────────┐
│                         WEBHOOK MODE                                │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Event Grid ────── Push ──────▶ Logic App                          │
│                            (Real-time)                              │
│                                                                     │
│   Pros:                                                             │
│   ✓ Real-time response (seconds)                                    │
│   ✓ No polling overhead                                             │
│   ✓ Lower cost                                                      │
│   ✓ Immediate processing                                            │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Polling Mode (Pull - Legacy)

┌─────────────────────────────────────────────────────────────────────┐
│                         POLLING MODE                                │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Logic App ────── Poll every X ──────▶ Event Grid                  │
│                   minutes                  (Not recommended)        │
│                                                                     │
│   Cons:                                                             │
│   ✗ Delay in processing (X minutes)                                 │
│   ✗ Higher cost (continuous polling)                                │
│   ✗ May miss events                                                 │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Enable Webhook

The Event Grid trigger automatically uses webhook push when:

  • Logic App is in the same region as the event source
  • Logic App has HTTPS endpoint (not HTTP)
  • Premium/Standard hosting plan is used

Processing Events

Access Event Data

{
  "fullEvent": "@triggerBody()",
  "eventType": "@triggerBody()?['eventType']",
  "subject": "@triggerBody()?['subject']",
  "eventTime": "@triggerBody()?['eventTime']",
  "dataUrl": "@triggerBody()?['data']?['api']",
  "blobUrl": "@triggerBody()?['data']?['url']"
}

Parse Event Data

{
  "Parse_Event": {
    "type": "ParseJson",
    "inputs": {
      "content": "@triggerBody()"
    },
    "schema": {
      "type": "object",
      "properties": {
        "eventType": { "type": "string" },
        "subject": { "type": "string" },
        "data": {
          "type": "object",
          "properties": {
            "url": { "type": "string" },
            "api": { "type": "string" }
          }
        }
      }
    }
  }
}

Filter Events

{
  "Filter_Events": {
    "type": "Condition",
    "expression": "@equals(triggerBody()?['eventType'], 'Microsoft.Storage.BlobCreated')",
    "actions": {
      "Process_Blob": { ... }
    }
  }
}

Real-World Examples

Example 1: Blob Upload Processing Pipeline

┌─────────────────────────────────────────────────────────────────────┐
│              BLOB UPLOAD PROCESSING WORKFLOW                        │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   [Trigger: Event Grid]                                             │
│   │  Event: Microsoft.Storage.BlobCreated                           │
│   │  Filter: uploads/*                                              │
│   └──────┬────────────────────────────────────────────────────────┘ │
│          │                                                          │
│          ▼                                                          │
│   [Get Blob Content]                                                │
│   │  URI: from trigger                                              │
│   └──────┬────────────────────────────────────────────────────────┘ │
│          │                                                          │
│          ▼                                                          │
│   [Parse CSV/JSON]                                                  │
│   └──────┬────────────────────────────────────────────────────────┘ │
│          │                                                          │
│          ▼                                                          │
│   [Switch - File Type]                                              │
│   ├─ CSV: [Insert to SQL Database]                                  │
│   ├─ JSON: [Process as Orders]                                      │
│   └─ XML: [Transform to JSON]                                       │
│   └──────┬────────────────────────────────────────────────────────┘ │
│          │                                                          │
│          ▼                                                          │
│   [Send Success Email]                                              │
│   └──────┬────────────────────────────────────────────────────────  │
│          │                                                          │
│          ▼                                                          │
│   [Update Status to Table]                                          │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Example 2: VM State Change Notifications

{
  "trigger": {
    "type": "EventGridTrigger",
    "inputs": {
      "subscription": {
        "subscriptionName": "production-sub"
      },
      "resourceType": "Microsoft.Compute/virtualMachines",
      "resourceName": "prod-vm-01",
      "eventTypes": [
        "Microsoft.Compute/virtualMachines/write",
        "Microsoft.Compute/virtualMachines/deallocation"
      ]
    }
  },
  "actions": {
    "Log_Event": {
      "type": "AzureTable",
      "inputs": {
        "method": "post",
        "path": "/tables/vm-events",
        "body": {
          "PartitionKey": "@triggerBody()?['eventType']",
          "RowKey": "@guid()",
          "vmName": "@triggerBody()?['subject']",
          "eventTime": "@triggerBody()?['eventTime']",
          "newState": "@triggerBody()?['data']?['newState']",
          "oldState": "@triggerBody()?['data']?['oldState']"
        }
      }
    },
    "Notify_Team": {
      "type": "Condition",
      "expression": "@equals(triggerBody()?['eventType'], 'Microsoft.Compute/virtualMachines/deallocation')",
      "actions": {
        "Send_Slack": {
          "type": "Slack",
          "inputs": {
            "message": "VM deallocated: @triggerBody()?['subject']"
          }
        }
      }
    }
  }
}

Example 3: Custom Topic Events

{
  "trigger": {
    "type": "EventGridTrigger",
    "inputs": {
      "topic": "/subscriptions/xxx/resourceGroups/my-rg/providers/Microsoft.EventGrid/topics/orders-topic"
    }
  },
  "actions": {
    "Process_Order": {
      "type": "Switch",
      "expression": "@triggerBody()?['eventType']",
      "cases": {
        "Order.Created": {
          "actions": {
            "Create_Order_Record": {
              "type": "Sql",
              "inputs": {
                "databaseName": "ordersdb",
                "query": "INSERT INTO orders VALUES (...)"
              }
            }
          }
        },
        "Order.Shipped": {
          "actions": {
            "Update_Status": {
              "type": "Sql",
              "inputs": {
                "databaseName": "ordersdb",
                "query": "UPDATE orders SET status='Shipped' WHERE id=..."
              }
            },
            "Send_Notification": {
              "type": "SendEmail"
            }
          }
        }
      }
    }
  }
}

Best Practices

PracticeDescription
Use webhook modeEnable real-time processing
Filter eventsSubscribe only to needed events
Parse onceExtract event data early in workflow
Add error handlingHandle failed events gracefully
Log all eventsTrack for debugging and auditing

Performance Considerations

  • Use Standard plan for high throughput
  • Implement ** batching** for many events
  • Set up dead-letter for failed processing
  • Monitor trigger frequency in Analytics

Monitoring

Trigger Runs

# Get Logic App trigger history
az logic workflow run list \
  --resource-group my-rg \
  --name my-logic-app \
  --query "[].{Status: status, Start: startTime, Trigger: triggerName}"

Application Insights

traces
| where timestamp > ago(1h)
| where customDimensions.Category == "LogicApp"
| project timestamp, message, customDimensions

Related Topics


Azure Integration Hub - Intermediate Level