Create a function that’s triggered by Blob storage

  1. Home
  2. Create a function that’s triggered by Blob storage

This tutorial will help you in Creating a function that’s triggered by Blob storage. You will Learn how to create a function triggered when files are uploaded to or updated in a Blob storage container.

Creating a function that’s triggered by Blob storage

  1. Log in to the Azure portal (https://portal.azure.com).
  2. Click “Create a resource” in the left-hand navigation bar and select “Function App”.
  3. In the “Function App” blade, provide a unique name for your Function App and choose a subscription, resource group, and hosting plan. You can also configure the storage account settings and choose a runtime stack.
  4. Click “Create” to create the Function App.
  5. Once the Function App is created, click on the “Functions” blade and select “New Function”.
  6. Choose “Azure Blob Storage trigger” as the function template and provide a name for your function. You can also choose to create a new storage account or use an existing one.
  7. In the “Azure Blob Storage trigger” configuration window, specify the Blob storage container you want to monitor and select the trigger type. You can choose to trigger the function when a blob is added, modified or deleted. You can also specify a filter to only trigger the function for specific file types or file names.
  8. Click “Create” to create the function.
  9. In the function editor window, write the code that will be executed when the function is triggered by a Blob storage event. You can use the input binding to read the contents of the Blob and perform any necessary processing, such as data transformation, parsing or validation.
  10. Save your function code and click “Run” to test it with a sample Blob. You can also use the “Test/Run” tab to specify input and output bindings and test your function with real-world data.
  11. Once you’re satisfied with your function, you can deploy it to your Function App by clicking “Deploy” in the upper-right corner of the editor window. You can also configure the function settings, such as environment variables, application settings, and access controls.
  12. To monitor your function and view its logs, go to the “Monitor” tab and select “Logs”. You can use the log data to diagnose issues and optimize the performance of your function.

Creating an Azure Function app

Firstly, Go to Azure portal menu or the Home page, choose Create a resource.

Now, In the New page, choose Compute > Function App.

Also, On the Basics page, you use the function app settings as specified in the following table.

SettingSuggested valueDescription
SubscriptionYour subscriptionThe subscription under which this new function app is created.
Resource GroupmyResourceGroupName for the new resource group in which to create your function app.
Function App nameGlobally unique nameName that identifies your new function app. Valid characters are a-z (case insensitive), 0-9, and -.
PublishCodeOption to publish code files or a Docker container.
Runtime stackPreferred languageChoose a runtime that supports your favorite function programming language. Choose .NET Core for C# and F# functions.
VersionVersion numberChoose the version of your installed runtime.
RegionPreferred regionChoose a region near you or near other services your functions access.
Basics
Image source – Microsoft

Further steps

choose Next : Hosting. Fill in the following information on the Hosting page.

SettingSuggested valueDescription
Storage accountGlobally unique nameCreate a storage account used by your function app. Storage account names must be between 3 and 24 characters in length and can contain numbers and lowercase letters only. You can also use an existing account, which must meet the storage account requirements.
Operating systemPreferred operating systemAn operating system is pre-selected for you based on your runtime stack selection, but you can change the setting if necessary.
PlanConsumption (Serverless)Hosting plan that defines how resources are allocated to your function app. In the default Consumption plan, resources are added dynamically as required by your functions. In this serverless hosting, you pay only for the time your functions run. When you run in an App Service plan, you must manage the scaling of your function app.
Hosting
Image source – Microsoft

choose Next : Monitoring. On the Monitoring page, enter the following settings.

SettingSuggested valueDescription
Application InsightsDefaultCreates an Application Insights resource of the same App name in the nearest supported region. By expanding this setting or selecting Create new, you can change the Application Insights name or choose a different region in an Azure geography where you want to store your data.
Monitoring
Image source – Microsoft

On the Review + create page, go through your settings, and then choose Create to provision and deploy the function app.

choose the Notifications icon in the upper-right corner of the portal and watch for the Deployment succeeded message.

To see your new function app, select Go to the resource. You may also choose to pin it to your dashboard. It’s easy to return to this function app resource from your dashboard if you pin it.

You’ve successfully created your new function app.

Create the container

  1. In your function, on the Overview page, choose your resource group.
Select your Azure portal resource group.
Image source – Microsoft

Find and choose your resource group’s storage account.

Access the storage account.
Image source – Microsoft

Select Containers, and then select + Container.

Add container to your storage account in the Azure portal.
Image source – Microsoft

In the Name field, type samples-workitems, and then choose Create.

Name the storage container.
Image source – Microsoft

Now that you have a blob container, you can test the function by uploading a file to the container.

Create an Azure Blob storage triggered function

  • choose Functions, and then choose + Add to add a new function.
Choose a Function template in the Azure portal.
Image source – Microsoft
  • Select the Azure Blob Storage trigger template.
  • Use the settings as mentioned in the table below
SettingSuggested valueDescription
New FunctionUnique in your function appName of this blob triggered function.
Pathsamples-workitems/{name}Location in Blob storage being monitored. The file name of the blob is passed in the binding as the name parameter.
Storage account connectionAzureWebJobsStorageYou can use the storage account connection already being used by your function app, or create a new one.

choose Create Function to create your function.

Next, choose the samples-workitems container.

Test the function

  1. Firstly, get Back in the Azure portal, browse to your function expand the Logs at the bottom of the page and make sure that log streaming is working.
  2. Then In a separate browser window, go to your resource group in the Azure portal, and choose the storage account.
  3. Also,choose Containers, and then choose the samples-workitems container.
  4. choose Upload, and then select the folder icon to select a file to upload.
  5. Subsequently, Browse to a file on your local computer, such as an image file, choose the file. choose Open and then Upload.
  6. Lastly, Go back to your function logs and make sure that the blob has been read.

Last and important step is to clean up the resources when you are done.

Exam-AZ-305-Designing-Microsoft-Azure-Infrastructure-Solutions-tests-1

AZ-305 Exam Practice Questions

Question 1: ABC Inc. wants to create an Azure Function that gets triggered whenever a new blob is added to a specific container in their Blob storage account. Which type of trigger should they use?

A. Blob trigger

B. HTTP trigger

C. Queue trigger

D. Timer trigger

Answer: A. Blob trigger

Explanation: A Blob trigger is used to run an Azure Function whenever a new blob is added to a specified container in Blob storage. In this case, ABC Inc. wants to trigger the function whenever a new blob is added to a specific container, so they should use a Blob trigger.

Question 2: XYZ Corp. wants to create an Azure Function that gets triggered whenever a blob is deleted from a specific container in their Blob storage account. Which type of trigger should they use?

A. Blob trigger

B. HTTP trigger

C. Queue trigger

D. Timer trigger

Answer: None of the above.

Explanation: Currently, there is no built-in trigger for an Azure Function to be triggered when a blob is deleted from a specific container. However, you can use an Event Grid trigger to trigger an Azure Function when an event, such as blob deletion, occurs. In this case, XYZ Corp. should use an Event Grid trigger.

Question 3: PQR Enterprises wants to create an Azure Function that processes only specific types of blobs in their Blob storage account. Which attribute of the Blob trigger should they use to accomplish this?

A. path

B. name

C. metadata

D. direction

Answer: B. name

Explanation: The name attribute of the Blob trigger can be used to process only specific types of blobs in a Blob storage account. By specifying a pattern for the name attribute, you can ensure that the function is triggered only when a blob with a matching name is added to the specified container.

Question 4: DEF Corp. wants to create an Azure Function that processes multiple blobs at the same time whenever a new blob is added to a specific container in their Blob storage account. Which property of the Blob trigger should they use to accomplish this?

A. SingleBlob

B. MultipleBlobs

C. Batch

D. Sequential

Answer: B. MultipleBlobs

Explanation: The MultipleBlobs property of the Blob trigger can be used to process multiple blobs at the same time when a new blob is added to a specified container. By setting this property to true, the function can handle multiple blobs in a single invocation, which can improve the efficiency of the function.

Reference documentation – Create a function in Azure that’s triggered by Blob storage

Menu