Quickstart: Route Azure Cache for Redis events to web endpoint with the Azure portal

Azure Event Grid is an eventing service for the cloud. In this quickstart, you'll use the Azure portal to create an Azure Cache for Redis instance, subscribe to events for that instance, trigger an event, and view the results. Typically, you send events to an endpoint that processes the event data and takes actions. However, to simplify this quickstart, you'll send events to a web app that will collect and display the messages.

If you don't have an Azure subscription, create an Azure free account before you begin.

When you're finished, you'll see that the event data has been sent to the web app.

Azure Event Grid Viewer scaling in JSON format.

Create an Azure Cache for Redis cache instance

  1. To create a cache, sign in to the Azure portal. On the portal menu, select Create a resource.

    Sceenshot that shows the Create a resource option highlighted on the left navigation pane in the Azure portal.

  2. On the Get Started pane, enter Azure Cache for Redis in the search bar. In the search results, find Azure Cache for Redis, and then select Create.

    Screenshot that shows Azure Marketplace with Azure Cache for Redis in the search box, and the Create button is highlighted.

  3. On the New Redis Cache pane, on the Basics tab, configure the following settings for your cache:

    Setting Action Description
    Subscription Select your Azure subscription. The subscription to use to create the new instance of Azure Cache for Redis.
    Resource group Select a resource group, or select Create new and enter a new resource group name. A name for the resource group in which to create your cache and other resources. By putting all your app resources in one resource group, you can easily manage or delete them together.
    DNS name Enter a unique name. The cache name must be a string of 1 to 63 characters that contains only numbers, letters, and hyphens. The name must start and end with a number or letter, and it can't contain consecutive hyphens. Your cache instance's host name is \<DNS name>.redis.cache.windows.net.
    Location Select a location. An Azure region that is near other services that use your cache.
    Cache SKU Select a SKU. The SKU determines the size, performance, and feature parameters that are available for the cache. For more information, see Azure Cache for Redis overview.
    Cache size Select a cache size. For more information, see Azure Cache for Redis overview.
  4. Select the Networking tab or select Next: Networking.

  5. On the Networking tab, select a connectivity method to use for the cache.

  6. Select the Advanced tab or select Next: Advanced.

  7. On the Advanced pane, verify or select an authentication method based on the following information:

    Screenshot showing the Advanced pane and the available options to select.

    • By default, for a new Basic, Standard, or Premium cache, Microsoft Entra Authentication is enabled and Access Keys Authentication is disabled.
    • For Basic or Standard caches, you can choose the selection for a non-TLS port.
    • For Standard and Premium caches, you can choose to enable availability zones. You can't disable availability zones after the cache is created.
    • For a Premium cache, configure the settings for non-TLS port, clustering, managed identity, and data persistence.

    Important

    For optimal security, we recommend that you use Microsoft Entra ID with managed identities to authorize requests against your cache if possible. Authorization by using Microsoft Entra ID and managed identities provides superior security and ease of use over shared access key authorization. For more information about using managed identities with your cache, see Use Microsoft Entra ID for cache authentication.

  8. (Optional) Select the Tags tab or select Next: Tags.

  9. (Optional) On the Tags tab, enter a tag name and value if you want to categorize your cache resource.

  10. Select the Review + create button.

    On the Review + create tab, Azure automatically validates your configuration.

  11. After the green Validation passed message appears, select Create.

A new cache deployment occurs over several minutes. You can monitor the progress of the deployment on the Azure Cache for Redis Overview pane. When Status displays Running, the cache is ready to use.

Create a message endpoint

Before subscribing to the events for the cache instance, let's create the endpoint for the event message. Typically, the endpoint takes actions based on the event data. To simplify this quickstart, you'll deploy a pre-built web app that displays the event messages. The deployed solution includes an App Service plan, an App Service web app, and source code from GitHub.

  1. Select Deploy to Azure in GitHub README to deploy the solution to your subscription.

    Deploy to Azure button.

  2. On the Custom deployment page, do the following steps:

    1. For Resource group, select the resource group that you created when creating the cache instance. It will be easier for you to clean up after you're done with the tutorial by deleting the resource group.
    2. For Site Name, enter a name for the web app.
    3. For Hosting plan name, enter a name for the App Service plan to use for hosting the web app.
    4. Select the check box for I agree to the terms and conditions stated above.
    5. Select Purchase.
    Setting Suggested value Description
    Subscription Drop down and select your subscription. The subscription in which you want to create this web app.
    Resource group Drop down and select a resource group, or select Create new and enter a new resource group name. By putting all your app resources in one resource group, you can easily manage or delete them together.
    Site Name Enter a name for your web app. This value can't be empty.
    Hosting plan name Enter a name for the App Service plan to use for hosting the web app. This value can't be empty.
  3. Select Alerts (bell icon) in the portal, and then select Go to resource group.

    Azure portal deployment notification.

  4. On the Resource group page, in the list of resources, select the web app that you created. You'll also see the App Service plan and the cache instance in this list.

  5. On the App Service page for your web app, select the URL to navigate to the web site. The URL should be in this format: https://<your-site-name>.azurewebsites.net.

  6. Confirm that you see the site but no events have been posted to it yet.

    Empty Event Grid Viewer site.

Register the Event Grid resource provider

Unless you've used Event Grid before, you'll need to register the Event Grid resource provider. If you’ve used Event Grid before, skip to the next section.

In the Azure portal, do the following steps:

  1. On the left menu, select Subscriptions.

  2. Select the subscription you want to use for Event Grid from the subscription list.

  3. On the Subscription page, select Resource providers under Settings on the left menu.

  4. Search for Microsoft.EventGrid, and confirm that the Status is Not Registered.

  5. Select Microsoft.EventGrid in the provider list.

  6. Select Register on the command bar.

    Image showing the registration of Microsoft.EventGrid provider with the Azure subscription.

  7. Refresh to make sure the status of Microsoft.EventGrid is changed to Registered.

    Image showing the successful registration of Microsoft.EventGrid provider with the Azure subscription.

Subscribe to the Azure Cache for Redis instance

In this step, you'll subscribe to a topic to tell Event Grid which events you want to track, and where to send the events.

  1. In the portal, navigate to your cache instance that you created earlier.

  2. On the Azure Cache for Redis page, select Events on the left menu.

  3. Select Web Hook. You're sending events to your viewer app using a web hook for the endpoint.

    Azure portal Events page.

  4. On the Create Event Subscription page, enter the following:

    Setting Suggested value Description
    Name Enter a name for the event subscription. The value must be between 3 and 64 characters long. It can only contain letters, numbers, and dashes.
    Event Types Drop down and select which event type(s) you want to get pushed to your destination. For this quickstart, we'll be scaling our cache instance. Patching, scaling, import and export are the available options.
    Endpoint Type Select Web Hook. Event handler to receive your events.
    Endpoint Select Select an endpoint, and enter the URL of your web app and add api/updates to the home page URL (for example: https://cache.azurewebsites.net/api/updates), and then select Confirm Selection. This is the URL of your web app that you created earlier.
  5. Now, on the Create Event Subscription page, select Create to create the event subscription.

  6. View your web app again, and notice that a subscription validation event has been sent to it. Select the eye icon to expand the event data. Event Grid sends the validation event so the endpoint can verify that it wants to receive event data. The web app includes code to validate the subscription.

    Azure Event Grid Viewer.

Send an event to your endpoint

Now, let's trigger an event to see how Event Grid distributes the message to your endpoint. We'll be scaling your Azure Cache for Redis instance.

  1. In the Azure portal, navigate to your Azure Cache for Redis instance and select Scale on the left menu.

  2. Select the desired pricing tier from the Scale page and select Select.

    You can scale to a different pricing tier with the following restrictions:

    • You can't scale from a higher pricing tier to a lower pricing tier.
      • You can't scale from a Premium cache down to a Standard or a Basic cache.
      • You can't scale from a Standard cache down to a Basic cache.
    • You can scale from a Basic cache to a Standard cache but you can't change the size at the same time. If you need a different size, you can do a subsequent scaling operation to the desired size.
    • You can't scale from a Basic cache directly to a Premium cache. First, scale from Basic to Standard in one scaling operation, and then from Standard to Premium in a subsequent scaling operation.
    • You can't scale from a larger size down to the C0 (250 MB) size.

    While the cache is scaling to the new pricing tier, a Scaling status is displayed using Azure Cache for Redis on the left. When scaling is complete, the status changes from Scaling to Running.

  3. You've triggered the event, and Event Grid sent the message to the endpoint you configured when subscribing. The message is in the JSON format and it contains an array with one or more events. In the following example, the JSON message contains an array with one event. View your web app and notice that a ScalingCompleted event was received.

    Azure Event Grid Viewer scaling in JSON format.

Clean up resources

If you plan to continue working with this event, don't clean up the resources created in this quickstart. Otherwise, delete the resources you created in this quickstart.

Select the resource group, and select Delete resource group.

Next steps

Now that you know how to create custom topics and event subscriptions, learn more about what Event Grid can help you do: