Deploying Storage Queue Trigger Function
Tags: azure, serverless, azurefunctions, faas
Published: 2022-10-08 15:52:23

---
title: Deploying Storage Queue Trigger Function
published: true
date: 2022-10-08 12:35:18 UTC
tags: #azure #serverless #azurefunctions #faas
canonical_url: https://blog.cloudbuff.in/azure-functions-part-5
---

In the [previous article](https://dev.to/sjejurkar/azure-function-with-storage-queue-trigger-p4p), we created a function that gets triggered when a message arrives in a Azure Storage Queue. Using a storage emulator, we tested our function locally. Let's deploy it to Azure and test it in the cloud now.

## Create Storage Queue

When we [set up Azure Function App](https://dev.to/sjejurkar/deploying-our-first-function-to-azure-1kcb), we created a Storage Account and linked it to our Function App. We will use the same account to create a Storage Queue. In Azure Portal, let's go to our storage account.

![05_Portal_Storage_account.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665227785150/iWP20ok8d.png)

Click on the Storage Account name and then on `Queues` item in the left menu. List of queues is displayed on the right. There are no queues since we haven't created any yet. Click on `+ Queue` icon to create a new queue.

![06_Portal_Storage_add_queue.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665227901200/1gegPERfX.png)

Let's create a queue with name `blog-queue`. This is the name that we specified when we created `SimpleQueueFunction`. ![06_Portal_Storage_new_queue.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665227909427/VMRRmiiLh.png)

We should see a message indicating that the queue was created successfully. Next, let's deploy our function to Azure.

![07_Portal_Storage_queue.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665227920003/dgE6_QLpE.png)

## Deploy function

Let's go to Visual Studio Code and open the project that we worked with in our [last article](https://dev.to/sjejurkar/azure-function-with-storage-queue-trigger-p4p).

> If you haven't signed in to Azure from VS Code, checkout this [previous article](https://dev.to/sjejurkar/deploying-our-first-function-to-azure-1kcb) to see the steps for signing in.

Open the Command Palette using keyboard shortcut `Ctrl + Shift + P` (use `Cmd + Shift + P` on Mac) or `View > Command Palette...` menu option. Type `Azure Functions: Deploy` into text box and select `Azure Functions: Deploy to Function App...` option. ![16_VSCode_deploy_function.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1664553140554/lJQV6NWYB.png)

> You may get a pop-up message in VS Code asking you to set up your Azure account. If you had signed into Azure previously and get this message, open the command palette, type `Azure: Sign` and click the Sign Out task. It will then allow you to sign in again. ![21_VSCode_Azure_signOut.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665221220555/B1c7Gm6Qx.png)

A list of Function Apps defined in Azure will be displayed. As we have created only one Function App `blog-function-app`, we should see just that in the list. ![17_VSCode_deploy_select_fapp.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1664553148649/AgsvabezS.png)

When we select `blog-function-app` for deployment, there will be a warning saying the previous deployment will be overwritten. We will click `Deploy` to proceed.

![18_VSCode_deploy_fapp_warn.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1664554113584/jgudFOm7c.png)

A Terminal window should open in VS Code and we should soon see `Deployment to "blog-function-app" completed.` message pop-up.  
 ![18-2_VSCode_deploy_fapp_done.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1664558933331/2a8ae6RGv.png)

Our code has been deployed successfully. If we go back to Function App in Azure Portal and click on `Functions` menu item, we should see both `SimpleHttpFunction` and `SimpleQueueFunction` in the list.

![04_Portal_Function_list.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665220673038/gThWQRX1V.png)

Let's test our function by putting a message into the Storage Queue. First, let's enable the log stream so we can verify that our function is indeed getting triggered when a message is received in the queue. We will go to our Function App in Azure and click on `Log stream` item in the left menu. A terminal will open to the right and in a few moments we should see that it is connected to our Function App.

![08_Portal_Function_log_stream.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665229060362/9svhzNGJz.png)

Let's keep this browser tab open so we can come back to check log messages. We will duplicate this browser tab (hover over the current tab, do a right-click and click `Duplicate` option from the pop-up menu) and go to the Storage Queue that we created earlier. Clicking on `+ Add message` icon will open a pop-up window. Note that this window is similar to the window that we saw in Azure Storage Explorer tool. Let's use a simple JSON message `{ "msg": "Message from Azure Portal" }`. Add the message text and click OK to add it to the queue.

![08_Portal_queue_message.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665229288057/HK7fdi8Ww.png)

Now let's go back to the browser tab for log stream. We should see that the `SimpleQueueFunction` function was executed and the message from the queue is displayed in the logs.

![10_Portal_Function_log_stream_output.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665229896286/N3rHvvj1J.png)

Now let's verify that the logging also works the same way for `SimpleHttpFunction`. Open a new browser or tab, put URL `https://blog-function-app.azurewebsites.net/api/SimpleHttpFunction?name=Jack` into the address bar and press enter. If a message like the one below is displayed, it means our function was executed successfully. ![22_browser_invoke_2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1664559102015/0YR6_AVHG.png)

In the browser tab for log stream, we should see that the `SimpleHttpFunction` function was executed successfully and the log message was written to the log stream.

![10_Portal_Function_log_stream_output_2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665230001636/nMIoQ2vJ6.png)

## Stopping and starting Function App

If we are still in test mode, we should consider stopping our Function App when it is not being used. We can go to our Function App and stop it.

![10_Portal_stop_Function.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665230704943/sj3aOdY2r.png)

When we are ready to use it again, we can start our Function App back up. ![11_Portal_start_Function.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1665230715158/JwC46Zfub.png)

## Conclusion

In this article we deployed our simple function with Storage Queue trigger to Azure cloud.

We saw how to view the log stream of our Function App. While looking at logs this way is fine for testing, it is not a practical solution once the function is deployed and running. We simply cannot watch log stream all the time. Besides, it also means that we have to leave the browser tab open for the log stream to continue. In the next article, we will take a look at a much better solution for this. We will configure our Function App to send logs to a centralized location using Azure Log Analytics.