Skip to content

Latest commit

 

History

History
184 lines (126 loc) · 9.9 KB

functions-add-output-binding-storage-queue-cli.md

File metadata and controls

184 lines (126 loc) · 9.9 KB
title description ms.date ms.topic ms.devlang ms.custom zone_pivot_groups
Connect Azure Functions to Azure Storage using command line tools
Learn how to connect Azure Functions to an Azure Storage queue by adding an output binding to your command line project.
04/25/2024
quickstart
csharp
devx-track-python, mode-other, devx-track-extended-java, devx-track-js, devx-track-ts
programming-languages-set-functions

Connect Azure Functions to Azure Storage using command line tools

In this article, you integrate an Azure Storage queue with the function and storage account you created in the previous quickstart article. You achieve this integration by using an output binding that writes data from an HTTP request to a message in the queue. Completing this article incurs no additional costs beyond the few USD cents of the previous quickstart. To learn more about bindings, see Azure Functions triggers and bindings concepts.

Configure your local environment

::: zone pivot="programming-language-csharp"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end
::: zone pivot="programming-language-javascript"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end
::: zone pivot="programming-language-java"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end
::: zone pivot="programming-language-typescript"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end
::: zone pivot="programming-language-python"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end
::: zone pivot="programming-language-powershell"
Before you begin, you must complete the article, Quickstart: Create an Azure Functions project from the command line. If you already cleaned up resources at the end of that article, go through the steps again to recreate the function app and related resources in Azure.
::: zone-end

[!INCLUDE functions-cli-get-storage-connection]

::: zone pivot="programming-language-csharp"

Register binding extensions

::: zone-end

[!INCLUDE functions-register-storage-binding-extension-csharp]

[!INCLUDE functions-add-output-binding-cli]

::: zone pivot="programming-language-csharp"
[!INCLUDE functions-add-storage-binding-csharp-library]
::: zone-end
::: zone pivot="programming-language-java" [!INCLUDE functions-add-output-binding-java-cli] ::: zone-end

For more information on the details of bindings, see Azure Functions triggers and bindings concepts and queue output configuration.

Add code to use the output binding

With the queue binding defined, you can now update your function to receive the msg output parameter and write messages to the queue.

::: zone pivot="programming-language-python"
[!INCLUDE functions-add-output-binding-python] ::: zone-end

::: zone pivot="programming-language-javascript"

[!INCLUDE functions-add-output-binding-js] ::: zone-end

::: zone pivot="programming-language-typescript"
[!INCLUDE functions-add-output-binding-ts] ::: zone-end

::: zone pivot="programming-language-powershell"
[!INCLUDE functions-add-output-binding-powershell]
::: zone-end

::: zone pivot="programming-language-csharp"
[!INCLUDE functions-add-storage-binding-csharp-library-code] ::: zone-end

::: zone pivot="programming-language-java" [!INCLUDE functions-add-output-binding-java-code]

[!INCLUDE functions-add-output-binding-java-test-cli] ::: zone-end

Observe that you don't need to write any code for authentication, getting a queue reference, or writing data. All these integration tasks are conveniently handled in the Azure Functions runtime and queue output binding.

[!INCLUDE functions-run-function-test-local-cli]

[!INCLUDE functions-extension-bundles-info]

View the message in the Azure Storage queue

[!INCLUDE functions-add-output-binding-view-queue-cli]

Redeploy the project to Azure

Now that you've verified locally that the function wrote a message to the Azure Storage queue, you can redeploy your project to update the endpoint running on Azure.

::: zone pivot="programming-language-javascript,programming-language-typescript,programming-language-python,programming-language-powershell,programming-language-csharp" In the LocalFunctionsProj folder, use the func azure functionapp publish command to redeploy the project, replacing<APP_NAME> with the name of your app.

func azure functionapp publish <APP_NAME>

::: zone-end

::: zone pivot="programming-language-java"

In the local project folder, use the following Maven command to republish your project:

mvn azure-functions:deploy

::: zone-end

Verify in Azure

  1. As in the previous quickstart, use a browser or CURL to test the redeployed function.

    Copy the complete Invoke URL shown in the output of the publish command into a browser address bar, appending the query parameter &name=Functions. The browser should display the same output as when you ran the function locally.

    Run curl with the Invoke URL, appending the parameter &name=Functions. The output should be the same as when you ran the function locally.


  2. Examine the Storage queue again, as described in the previous section, to verify that it contains the new message written to the queue.

Clean up resources

After you've finished, use the following command to delete the resource group and all its contained resources to avoid incurring further costs.

az group delete --name AzureFunctionsQuickstart-rg

Next steps

You've updated your HTTP triggered function to write data to a Storage queue. Now you can learn more about developing Functions from the command line using Core Tools and Azure CLI:

::: zone pivot="programming-language-csharp"

::: zone-end ::: zone pivot="programming-language-javascript"

::: zone-end
::: zone pivot="programming-language-typescript"

::: zone-end
::: zone pivot="programming-language-python"

::: zone-end
::: zone pivot="programming-language-powershell"

::: zone-end