Create a function triggered by Azure Queue storage

Learn how to create a function triggered when messages are submitted to an Azure Storage queue.

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 Queue 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 QueueTrigger template for your desired language, and use the settings as specified in the table.

    Create the storage queue triggered function.

    Setting Suggested value Description
    Queue name myqueue-items Name of the queue to connect to in your Storage account.
    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 queue triggered function.
  3. Click Create to create your function.

Next, you connect to your Azure Storage account and create the myqueue-items storage queue.

Create the queue

  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.v

  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 Queues, click Create queue, type myqueue-items, and then press enter.

    Create a storage queue.

Now that you have a storage queue, you can test the function by adding a message to the queue.

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, Queues, and myqueue-items, then click Add message.

    Add a message to the queue.

  3. Type your "Hello World!" message in Message text and click OK.

  4. Wait for a few seconds, then go back to your function logs and verify that the new message has been read from the queue.

    View message in the logs.

  5. Back in Storage Explorer, click Refresh and verify that the message has been processed and is no longer in the queue.

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 message is added to a storage queue.

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

For more information about Queue storage triggers, see Azure Functions Storage queue bindings.