Bird
Raised Fist0
Azurecloud~10 mins

Event Grid subscriptions and filters in Azure - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

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
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an Event Grid subscription with a filter on the event type.

Azure
az eventgrid event-subscription create --name mySubscription --source-resource-id /subscriptions/123/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/myStorage [1] --endpoint https://myendpoint.com/api/events
Drag options to blanks, or click blank then click option'
A--included-event-types BlobCreated
B--included-event-types BlobDeleted
C--subject-begins-with /blobServices/default/containers/images/
D--subject-ends-with .jpg
Attempts:
3 left
💡 Hint
Common Mistakes
Using subject filters instead of event type filters.
Omitting the event type filter option.
2fill in blank
medium

Complete the code to add a subject filter that only accepts events where the subject begins with a specific path.

Azure
az eventgrid event-subscription create --name mySubscription --source-resource-id /subscriptions/123/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/myStorage --included-event-types BlobCreated [1] --endpoint https://myendpoint.com/api/events
Drag options to blanks, or click blank then click option'
A--subject-ends-with .png
B--subject-begins-with /blobServices/default/containers/images/
C--subject-contains images
D--subject-equals /blobServices/default/containers/images/
Attempts:
3 left
💡 Hint
Common Mistakes
Using --subject-ends-with instead of --subject-begins-with.
Using --subject-contains which is not a valid filter option.
3fill in blank
hard

Fix the error in the filter syntax to correctly filter events where the subject ends with '.jpg'.

Azure
az eventgrid event-subscription create --name mySubscription --source-resource-id /subscriptions/123/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/myStorage --included-event-types BlobCreated [1] --endpoint https://myendpoint.com/api/events
Drag options to blanks, or click blank then click option'
A--subject-ends-with .jpg
B--subject-begin-with .jpg
C--subject-endswith .jpg
D--subject-ends .jpg
Attempts:
3 left
💡 Hint
Common Mistakes
Misspelling the filter option name.
Using incorrect suffix filter syntax.
4fill in blank
hard

Fill both blanks to create an Event Grid subscription with filters for event type and subject prefix.

Azure
az eventgrid event-subscription create --name mySubscription --source-resource-id /subscriptions/123/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/myStorage [1] [2] --endpoint https://myendpoint.com/api/events
Drag options to blanks, or click blank then click option'
A--included-event-types BlobDeleted
B--subject-begins-with /blobServices/default/containers/videos/
C--included-event-types BlobCreated
D--subject-ends-with .mp4
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up event type and subject filter options.
Using incorrect filter values.
5fill in blank
hard

Fill all three blanks to create an Event Grid subscription with filters for event type, subject prefix, and subject suffix.

Azure
az eventgrid event-subscription create --name mySubscription --source-resource-id /subscriptions/123/resourceGroups/myRG/providers/Microsoft.Storage/storageAccounts/myStorage [1] [2] [3] --endpoint https://myendpoint.com/api/events
Drag options to blanks, or click blank then click option'
A--included-event-types BlobCreated
B--subject-begins-with /blobServices/default/containers/images/
C--subject-ends-with .png
D--included-event-types BlobDeleted
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong event type filter.
Confusing subject prefix and suffix filters.

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

  1. Step 1: Understand Event Grid subscriptions

    Subscriptions let you receive events from Azure services.
  2. Step 2: Role of filters in subscriptions

    Filters help select only the events you want, based on event type or subject.
  3. Final Answer:

    To receive only specific events based on criteria like event type or subject -> Option A
  4. 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

  1. Step 1: Identify subject prefix filter syntax

    The correct property to filter by subject prefix is "subjectBeginsWith".
  2. Step 2: Match the correct JSON snippet

    "filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } uses "subjectBeginsWith" with the correct path prefix.
  3. Final Answer:

    "filter": { "subjectBeginsWith": "/blobServices/default/containers/images" } -> Option A
  4. 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:
{ "subjectBeginsWith": "/devices/", "subjectEndsWith": "/temperature" }

Which event subject will be delivered to the subscriber?
medium
A. /sensors/device123/temperature
B. /devices/device123/humidity
C. /devices/device123/temperature
D. /devices/temperature/device123

Solution

  1. Step 1: Understand filter conditions

    The event subject must start with "/devices/" and end with "/temperature".
  2. Step 2: Check each option

    /devices/device123/temperature matches both start and end. Others fail one condition.
  3. Final Answer:

    /devices/device123/temperature -> Option C
  4. Quick Check:

    Subject starts with /devices/ and ends with /temperature = A [OK]
Hint: Match both start and end strings exactly [OK]
Common Mistakes:
  • Ignoring subjectEndsWith condition
  • Confusing similar paths
  • Assuming partial matches are enough
4. You wrote this filter in your Event Grid subscription:
{ "subjectBeginsWith": "/orders/", "subjectEndsWith": "/completed" }

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

  1. Step 1: Check filter syntax and support

    The JSON syntax is valid and Event Grid supports subject filters.
  2. 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.
  3. Final Answer:

    The subject filter is case-sensitive and event subjects differ in case -> Option D
  4. 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

  1. Step 1: Filter by event type

    The event type must be exactly "Microsoft.Storage.BlobCreated" to get blob creation events.
  2. Step 2: Filter by subject prefix for container

    The subject prefix for blobs in the "images" container is "/blobServices/default/containers/images/".
  3. Step 3: Combine filters correctly

    { "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } combines both eventType and subjectBeginsWith correctly.
  4. Final Answer:

    { "eventType": "Microsoft.Storage.BlobCreated", "subjectBeginsWith": "/blobServices/default/containers/images/" } -> Option B
  5. 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
  • Omitting container path in subject filter