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.
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.
- Open a browser.
- Navigate to the provided Azure Portal URL.
- Use the supplied username and password to authenticate.
- Create the Event Grid-Triggered Function
Starting in the Azure dashboard perform the following tasks:
- Open the navigation menu in the upper-left of the Portal.
- Click All resources. Wait for all the resources to appear.
- 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.
- Click the Functions menu item in the navigation tree on the left of the page.
- Click + Create near the top center of the page.
- In the panel that appears on the right of the page, select Azure Event Grid Trigger from the template list.
- In the New Function panel that appears on the right of the page, enter "MyEventGridTriggerFunction" as the name*.
- Click Create.
- Wait for the function to appear.
- Create the Event Grid Subscription
- In the left column of the MyEventGridTriggerFunction overview page, click on Integration.
- Click on Event Grid Trigger in the Trigger box.
- In the panel that appears on the right of the page, click on Create Event Grid Subscription.
- 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
- At the top of the azure portal, click on Home.
- Under the Navigate section, select All Resources.
- Click on the storage account resource which will begin with stg.
- In the left panel under Data Storage, click Containers.
- Click + Container.
- Enter images for the Name of the container in the panel that pops up.
- Click Create.
- At the top of the Azure Portal right next to the search bar, click on the Azure Cloud Shell icon.
- A panel will pop up at the bottom of the page. Adjust the size of the panel as needed and select bash.
- Next to the Subscription box, click on Show advanced settings.
- For the Cloud Shell region field, select West US.
- For the Resource Group field, leave Use existing selected.
- For the Storage account field, select Use existing.
- For the File share field, leave Create new selected and enter cshell for the name of the file share.
- 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.
Click on the images container.
In the panel that pops up, click the folder button to open the file browser.
Select a local file and then click Open. It is recommended to use a small text file or image.
In the shell, you should notice an API call is logged for the upload blob event just triggered.