Create a function triggered by Azure Blob storage

Learn how to create a function triggered when files are uploaded to or updated in Azure Blob storage.

View message in the logs.

Prerequisites

Add Function Apps to your portal favorites

If you haven't already done so, add Function Apps to your favorites in the Azure portal. This makes it easier to find your function apps. If you have already done this, skip to the next section.

  1. Log in to the Azure portal.

  2. Click the arrow at the bottom left to expand all services, type Functions in the Filter field, and then click the star next to Function Apps.

    Create function app in the Azure portal

    This adds the Functions icon to the menu on the left of the portal.

  3. Close the menu, then scroll down to the bottom to see the Functions icon. Click this icon to see a list of all your function apps. Click your function app to work with functions in this app.

Create an Azure Function app

  1. Click the New button found on the upper left-hand corner of the Azure portal.

  2. Click Compute > Function App, select your Subscription. Then, use the function app settings as specified in the table.

    Create function app in the Azure portal

    Setting Suggested value Description
    App name Globally unique name Name that identifies your new function app.
    Resource Group myResourceGroup Name for the new resource group in which to create your function app.
    Hosting plan Consumption plan 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. You only pay for the time your functions run.
    Location West Europe Choose a location near you or near other services your functions will access.
    Storage account Globally unique name Name of the new storage account used by your function app. You can also use an existing account.
  3. Click Create to provision and deploy the new function app.

Function app successfully created.

Next, you create a function in the new function app.

Create a Blob storage triggered function

  1. Expand your function app and click the + button next to Functions. If this is the first function in your function app, select Custom function. This displays the complete set of function templates.

    Functions quickstart page in the Azure portal

  2. Select the BlobTrigger template for your desired language, and use the settings as specified in the table.

    Create the Blob storage triggered function.

    Setting Suggested value Description
    Path mycontainer/{name} Location in Blob storage being monitored. The file name of the blob is passed in the binding as the name parameter.
    Storage account connection AzureWebJobStorage You can use the storage account connection already being used by your function app, or create a new one.
    Name your function Unique in your function app Name of this blob triggered function.
  3. Click Create to create your function.

Next, you connect to your Azure Storage account and create the mycontainer container.

Create the container

  1. In your function, click Integrate, expand Documentation, and copy both Account name and Account key. You use these credentials to connect to the storage account. If you have already connected your storage account, skip to step 4.

    Get the Storage account connection credentials.

  2. Run the Microsoft Azure Storage Explorer tool, click the connect icon on the left, choose Use a storage account name and key, and click Next.

    Run the Storage Account Explorer tool.

  3. Enter the Account name and Account key from step 1, click Next and then Connect.

    Enter the storage credentials and connect.

  4. Expand the attached storage account, right-click Blob containers, click Create blob container, type mycontainer, and then press enter.

    Create a storage queue.

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

Test the function

  1. Back in the Azure portal, browse to your function expand the Logs at the bottom of the page and make sure that log streaming isn't paused.

  2. In Storage Explorer, expand your storage account, Blob containers, and mycontainer. Click Upload and then Upload files....

    Upload a file to the blob container.

  3. In the Upload files dialog box, click the Files field. Browse to a file on your local computer, such as an image file, select it and click Open and then Upload.

  4. Go back to your function logs and verify that the blob has been read.

    View message in the logs.

    Note

    When your function app runs in the default Consumption plan, there may be a delay of up to several minutes between the blob being added or updated and the function being triggered. If you need low latency in your blob triggered functions, consider running your function app in an App Service plan.

Clean up resources

Other quick starts in this collection build upon this quick start. If you plan to continue on to work with subsequent quick starts or with the tutorials, do not clean up the resources created in this quick start.

If you do not plan to continue, click the Resource group for the function app in the portal, and then click Delete.

Select the resource group to delete from the function app.

Next steps

You have created a function that runs when a blob is added to or updated in Blob storage.

Learn how to create functions with other kinds of triggers or how to integrate functions with other Azure services.

For more information about Blob storage triggers, see Azure Functions Blob storage bindings.