Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Event Grid Subscriptions and Filters
📖 Scenario: You are setting up an Azure Event Grid system to handle events from a storage account. You want to create subscriptions that only receive specific types of events to reduce unnecessary processing.
🎯 Goal: Build an Azure Event Grid subscription with filters that only allow events of a certain type to be delivered to a webhook endpoint.
📋 What You'll Learn
Create a variable with the event subscription name
Add a filter configuration to allow only 'BlobCreated' events
Create the Event Grid subscription with the filter and endpoint
Complete the subscription configuration with the correct scope and destination
💡 Why This Matters
🌍 Real World
Filtering events in Azure Event Grid helps reduce unnecessary processing and costs by delivering only relevant events to subscribers.
💼 Career
Cloud engineers and architects often configure event-driven architectures using Event Grid subscriptions and filters to build scalable and efficient systems.
Progress0 / 4 steps
1
Create the event subscription name variable
Create a variable called event_subscription_name and set it to the string "storageBlobCreatedSubscription".
Azure
Hint
Use a simple assignment statement to create the variable with the exact string value.
2
Add a filter configuration for event types
Create a dictionary called filter_config with a key included_event_types set to a list containing the string "Microsoft.Storage.BlobCreated".
Azure
Hint
Use a dictionary with the key exactly as included_event_types and the value as a list with one string.
3
Create the Event Grid subscription configuration
Create a dictionary called event_subscription_config with keys name, destination, and filter. Set name to event_subscription_name, destination to a dictionary with endpoint_type set to "WebHook" and endpoint_url set to "https://mywebhook.example.com/api/events", and filter set to filter_config.
Azure
Hint
Use nested dictionaries to represent the destination and include the filter dictionary as is.
4
Complete the subscription with scope and create command
Create a variable called scope and set it to the string "/subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/myResourceGroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount". Then create a dictionary called event_subscription_request with keys scope set to scope and properties set to event_subscription_config.
Azure
Hint
Use the exact resource ID string for scope and nest the event_subscription_config under properties.
Practice
(1/5)
1. What is the main purpose of using filters in Azure Event Grid subscriptions?
easy
A. To receive only specific events based on criteria like event type or subject
B. To increase the number of events sent to subscribers
C. To block all events from being delivered
D. To change the event data before delivery
Solution
Step 1: Understand Event Grid subscriptions
Subscriptions let you receive events from Azure services.
Step 2: Role of filters in subscriptions
Filters help select only the events you want, based on event type or subject.
Final Answer:
To receive only specific events based on criteria like event type or subject -> Option A
Quick Check:
Filters select events = B [OK]
Hint: Filters pick events you want, ignoring others [OK]
Common Mistakes:
Thinking filters increase event volume
Believing filters block all events
Assuming filters modify event data
2. Which of the following is the correct JSON snippet to filter events by subject prefix in an Event Grid subscription?
easy
A. "filter": { "subjectBeginsWith": "/blobServices/default/containers/images" }
B. "filter": { "subjectEndsWith": "/blobServices/default/containers/images" }
C. "filter": { "eventType": "Microsoft.Storage.BlobCreated" }
D. "filter": { "subjectContains": "images" }
Solution
Step 1: Identify subject prefix filter syntax
The correct property to filter by subject prefix is "subjectBeginsWith".
Step 2: Match the correct JSON snippet
"filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } uses "subjectBeginsWith" with the correct path prefix.
Final Answer:
"filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } -> Option A
Quick Check:
Prefix filter uses subjectBeginsWith = A [OK]
Hint: Prefix filters use subjectBeginsWith property [OK]
Common Mistakes:
Confusing subjectEndsWith with subjectBeginsWith
Using eventType instead of subject filter
Using subjectContains which is not valid
3. Given this Event Grid subscription filter configuration:
But no events are received even though events exist. What is the likely issue?
medium
A. The subscription is disabled
B. The filter syntax is invalid JSON
C. Event Grid does not support subject filters
D. The subject filter is case-sensitive and event subjects differ in case
Solution
Step 1: Check filter syntax and support
The JSON syntax is valid and Event Grid supports subject filters.
Step 2: Consider case sensitivity and subscription status
Subject filters are case-sensitive; if event subjects differ in case, no match occurs. Subscription being disabled would stop all events, but question implies filter issue.
Final Answer:
The subject filter is case-sensitive and event subjects differ in case -> Option D
Quick Check:
Subject filters are case-sensitive = D [OK]
Hint: Remember filters are case-sensitive in Event Grid [OK]
Common Mistakes:
Assuming filters ignore case
Blaming JSON syntax without checking
Ignoring subscription status
5. You want to create an Event Grid subscription that only receives events of type Microsoft.Storage.BlobCreated where the blob is in the container named images. Which filter configuration achieves this?
hard
A. { "eventType": "Microsoft.Storage.BlobDeleted", "subjectBeginsWith": "/blobServices/default/containers/images/" }
B. { "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" }
C. { "eventType": "Microsoft.Storage.BlobCreated", "subjectEndsWith": "/images" }
D. { "eventType": "Microsoft.Storage.BlobCreated" }
Solution
Step 1: Filter by event type
The event type must be exactly "Microsoft.Storage.BlobCreated" to get blob creation events.
Step 2: Filter by subject prefix for container
The subject prefix for blobs in the "images" container is "/blobServices/default/containers/images/".
Step 3: Combine filters correctly
{ "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } combines both eventType and subjectBeginsWith correctly.
Final Answer:
{ "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } -> Option B
Quick Check:
Event type and subject prefix filter combined = C [OK]
Hint: Combine eventType and subjectBeginsWith for precise filtering [OK]
Common Mistakes:
Using wrong event type
Using subjectEndsWith instead of subjectBeginsWith