Create an Azure Function to Listen to Blob Created Events

45 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we use the Azure Portal to create an Event Grid-triggered Azure Function that will be invoked when a blob is created in a storage account.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Log In to the Azure Portal

Log in to the Azure Portal using the username and password supplied by the lab.

  1. Open a browser.
  2. Navigate to the provided Azure Portal URL.
  3. Use the supplied username and password to authenticate.
Create the Event Grid-Triggered Function

Starting in the Azure dashboard perform the following tasks:

  1. Open the navigation menu in the upper-left of the Portal.
  2. Click All resources. Wait for all the resources to appear.
  3. In the list, click on the app service that has a name that starts with fa-. This will open the overview page of the function app service.
  4. Click the Functions menu item in the navigation tree on the left of the page.
  5. Click + Create near the top center of the page.
  6. In the panel that appears on the right of the page, select Azure Event Grid Trigger from the template list.
  7. In the New Function panel that appears on the right of the page, enter "MyEventGridTriggerFunction" as the name*.
  8. Click Create.
  9. Wait for the function to appear.
Create the Event Grid Subscription
  1. In the left column of the MyEventGridTriggerFunction overview page, click on Integration.
  2. Click on Event Grid Trigger in the Trigger box.
  3. In the panel that appears on the right of the page, click on Create Event Grid Subscription.
  4. On the Basic information page that appears for the Event Subscription, modify the following fields and click on Create:
    • Name: blobevent
    • Topic Types: Storage Accounts (Blob & GPv2)
    • Subscription: Select the only option available
    • Resource Group: Select the only option available
    • Resource: Select the only option available
    • System Topic Name: BlobEvents
Create a container in the Storage Account and Set up Cloud Shell
  1. At the top of the azure portal, click on Home.
  2. Under the Navigate section, select All Resources.
  3. Click on the storage account resource which will begin with stg.
  4. In the left panel under Data Storage, click Containers.
  5. Click + Container.
  6. Enter images for the Name of the container in the panel that pops up.
  7. Click Create.
  8. At the top of the Azure Portal right next to the search bar, click on the Azure Cloud Shell icon.
  9. A panel will pop up at the bottom of the page. Adjust the size of the panel as needed and select bash.
  10. Next to the Subscription box, click on Show advanced settings.
  11. For the Cloud Shell region field, select West US.
  12. For the Resource Group field, leave Use existing selected.
  13. For the Storage account field, select Use existing.
  14. For the File share field, leave Create new selected and enter cshell for the name of the file share.
  15. Click Create storage and a panel will open up at the bottom of the azure portal page. Adjust the shell as needed.
Upload a File to the Images Container and Examine the Function Logs to Verify It Ran

In Cloud Shell, type in and run the following command replacing your_app_name and your_resource_group field with your unique app name and resource group values:

az webapp log tail –name your_app_name –resource-group your_resource_group

Note: If you hit tab after the name and resource group fields, it will populate with the only available option.

  1. Click on the images container.

  2. Click Upload.

  3. In the panel that pops up, click the folder button to open the file browser.

  4. Select a local file and then click Open. It is recommended to use a small text file or image.

  5. Click Upload.

  6. In the shell, you should notice an API call is logged for the upload blob event just triggered.

Additional Resources

Your employer needs to process images uploaded to a blob container. You decide to create an Azure Function that is triggered by an Event Grid wired to blob-created events in the storage account. To test the concept, you create the function, configure the Event Grid subscription, and write the event data to the functions log.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?