Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Sameer Jejurkar
Sameer Jejurkar

Posted on • Originally published atblog.cloudbuff.in on

     

Deploying Storage Queue Trigger Function

In theprevious article, 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 weset up Azure Function App, 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

Click on the Storage Account name and then onQueues 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

Let's create a queue with nameblog-queue. This is the name that we specified when we createdSimpleQueueFunction.06_Portal_Storage_new_queue.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

Deploy function

Let's go to Visual Studio Code and open the project that we worked with in ourlast article.

If you haven't signed in to Azure from VS Code, checkout thisprevious article to see the steps for signing in.

Open the Command Palette using keyboard shortcutCtrl + Shift + P (useCmd + Shift + P on Mac) orView > Command Palette... menu option. TypeAzure Functions: Deploy into text box and selectAzure Functions: Deploy to Function App... option.16_VSCode_deploy_function.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, typeAzure: Sign and click the Sign Out task. It will then allow you to sign in again.21_VSCode_Azure_signOut.png

A list of Function Apps defined in Azure will be displayed. As we have created only one Function Appblog-function-app, we should see just that in the list.17_VSCode_deploy_select_fapp.png

When we selectblog-function-app for deployment, there will be a warning saying the previous deployment will be overwritten. We will clickDeploy to proceed.

18_VSCode_deploy_fapp_warn.png

A Terminal window should open in VS Code and we should soon seeDeployment to "blog-function-app" completed. message pop-up.

18-2_VSCode_deploy_fapp_done.png

Our code has been deployed successfully. If we go back to Function App in Azure Portal and click onFunctions menu item, we should see bothSimpleHttpFunction andSimpleQueueFunction in the list.

04_Portal_Function_list.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 onLog 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

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 clickDuplicate 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

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

10_Portal_Function_log_stream_output.png

Now let's verify that the logging also works the same way forSimpleHttpFunction. Open a new browser or tab, put URLhttps://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

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

10_Portal_Function_log_stream_output_2.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

When we are ready to use it again, we can start our Function App back up.11_Portal_start_Function.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.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Solutions Architect || Cloud Architect || AWS Certified
  • Joined

More fromSameer Jejurkar

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp