You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-connector/tutorial-python-functions-storage-blob-as-input.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
-
title: 'Tutorial: Python function with Azure Blob Storage as input'
2
+
title: 'Tutorial: Python Function with Azure Blob Storage as input'
3
3
description: Learn how you can connect a Python function to a storage blob as input using Service Connector in Azure.
4
4
author: houk-ms
5
5
ms.author: honc
6
6
ms.service: service-connector
7
7
ms.custom: devx-track-python
8
8
ms.topic: tutorial
9
-
ms.date: 10/22/2024
9
+
ms.date: 12/05/2025
10
10
#customer intent: As a developer, I want to configure a Python function with Storage Blob as input function binding so that I can process and manage large volumes of data stored in Azure Blob Storage.
11
11
---
12
12
# Tutorial: Python function with Azure Blob Storage as input
@@ -26,12 +26,12 @@ An overview of the function project components in this tutorial:
| Function Binding | HTTP trigger, Storage Blob as Input |
29
+
| Function Binding | HTTP trigger, Storage Blob as Input |
30
30
| Local Project Auth Type | Connection String |
31
31
| Cloud Function Auth Type | System-Assigned Managed Identity |
32
32
33
33
> [!WARNING]
34
-
> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
34
+
> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a high degree of trust in the application, and carries risks that aren't present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
35
35
36
36
## Prerequisites
37
37
@@ -42,36 +42,36 @@ An overview of the function project components in this tutorial:
42
42
43
43
## Create a Python function project
44
44
45
-
Follow the [tutorial to create a local Azure Functions project](../azure-functions/how-to-create-function-vs-code.md?pivot=programming-language-python?pivots=python-mode-configuration#create-an-azure-functions-project), and provide the following information at the prompts:
45
+
Follow the [tutorial to create a local Azure Functions project](../azure-functions/how-to-create-function-vs-code.md?pivot=programming-language-python?pivots=python-mode-configuration#create-an-azure-functions-project). Provide the following information at the prompts:
|**Select a language**| Choose `Python`. (v1 programming language model) |
49
+
|**Select a language**| Choose `Python`. (v1 programming language model) |
50
50
|**Select a Python interpreter to create a virtual environment**| Choose your preferred Python interpreter. If an option isn't shown, type in the full path to your Python binary. |
51
-
|**Select a template for your project's first function**| Choose `HTTP trigger`. |
52
-
|**Provide a function name**| Enter `BlobStorageInputFunc`. |
53
-
|**Authorization level**| Choose `Anonymous`, which lets anyone call your function endpoint. |
51
+
|**Select a template for your project's first function**| Choose `HTTP trigger`. |
52
+
|**Provide a function name**| Enter `BlobStorageInputFunc`. |
53
+
|**Authorization level**| Choose `Anonymous`, which lets anyone call your function endpoint. |
54
54
55
-
You have created a Python function project with an HTTP trigger.
55
+
With this information, Visual Studio Code generates a Python function project with an HTTP trigger.
56
56
57
57
## Add a Blob Storage input binding
58
58
59
-
Binding attributes are defined in the *function.json* file for a given function. To create a binding, right-click (Ctrl+click on macOS) the `function.json` file in your function folder and choose **Add binding...**. Follow the prompts to define the following binding properties for the new binding:
59
+
Binding attributes are defined in the *function.json* file for a given function. To create a binding, right-click the `function.json` file in your function folder and choose **Add binding...**. Follow the prompts to define the following binding properties for the new binding:
|**Select binding direction**|`in`| The binding is an input binding. |
64
64
|**Select binding with direction...**|`Azure Blob Storage`| The binding is an Azure Storage blob binding. |
65
65
|**The name used to identify this binding in your code**|`inputBlob`| Name that identifies the binding parameter referenced in your code. |
66
66
|**The path within your storage account from which the blob will be read**|`testcontainer/test.txt`| The blob path your function read as input. Prepare a file named `test.txt`, with a `Hello, World!` as the file content. Create a container named `testcontainer `, and upload the file to the container. |
67
-
|**Select setting from "local.setting.json"**|`Create new local app settings`| Select the Storage Account your function reads as input. Visual Studio Code retrieves its connection string for local project connection. |
67
+
|**Select setting from "local.setting.json"**|`Create new local app settings`| Select the Storage Account your function reads as input. Visual Studio Code retrieves its connection string for the local project connection. |
68
68
69
69
To check the binding was added successfully,
70
70
71
-
1. Open the `BlobStorageInputFunc/function.json` file, check that a new binding with `type: blob` and `direction: in` was added into this file.
72
-
1. Open the `local.settings.json` file, check that a new key-value pair `<your-storage-account-name>_STORAGE: <your-storage-account-connection-string>` that contains your storage account connection string was added into this file.
71
+
1. Open the `BlobStorageInputFunc/function.json` file, and check that a new binding with `type: blob` and `direction: in` was added into this file.
72
+
1. Open the `local.settings.json` file, and check that a new key-value pair `<your-storage-account-name>_STORAGE: <your-storage-account-connection-string>` that contains your storage account connection string was added into this file.
73
73
74
-
After the binding is added, update your function codes to consume the binding by replacing `BlobStorageInputFunc/__init__.py` with the Python file here.
74
+
After the binding is added, update your function code to consume the binding by replacing the `BlobStorageInputFunc/__init__.py`file with the following Python file:
Follow the [tutorial](../azure-functions/how-to-create-function-vs-code.md?pivot=programming-language-python?pivots=python-mode-configuration#run-the-function-locally) to run the function locally and verify the blob input.
88
88
89
-
1.Select the storage account you used when creating the Azure Function resource if you're prompted to connect to Storage. It is for Azure Function runtime's internal use, and isn't necessarily the same with the one you use for input.
90
-
1. To start the function locally, press `<kbd>`F5 `</kbd>` or select the **Run and Debug** icon in the left-hand side Activity bar.
91
-
1. To verify the function can read the blob, rightclick `Execute Function Now...` on the function in the Visual Studio Code **WORKSPACE** and check the function response. The response message should contain the content in your blob file.
89
+
1.If you're prompted to connect to storage, select the storage account you chose when creating the Azure Function resource. This storage account is used for Azure Function's internal use, and isn't necessarily the same as the storage account you use for the input.
90
+
1. To start the function locally, press <kbd>F5</kbd> or select the **Run and Debug** icon in the left-hand side Activity bar.
91
+
1. To verify the function can read the blob, right-click `Execute Function Now...` on the function in the Visual Studio Code **WORKSPACE** and check the function response. The response message should contain the content in your blob file.
92
92
93
93
## Create a connection using Service Connector
94
94
95
-
You just ran the project and verified the function locally, and your local project connects to your storage blob using a connection string.
95
+
In the last step, you ran the function locally and verified that your local project connects to your storage blob using a connection string.
96
96
97
-
Now you'll learn how to configure the connection between the Azure Function and Azure Blob Storage, so that your function can read the blob after being deployed to the cloud. In the cloud environment, we demonstrate how to authenticate using a system-assigned managed identity.
97
+
Next, you learn how to configure the connection between the Azure Function and Azure Blob Storage. Once your function is deployed to the cloud, this connection allows your function to read the blob. Then, in the cloud environment, we demonstrate how to authenticate using a system-assigned managed identity.
98
98
99
-
1. Open the `function.json` file in your local project, change the value of the `connection` property in `bindings` to be `MyBlobInputConnection`.
99
+
1. Open the `function.json` file in your local project, and change the value of the `connection` property in `bindings` to be `MyBlobInputConnection`.
100
100
1. Run the following Azure CLI command to create a connection between your Azure Function and your Azure Storage.
You have created a connection between Azure Function and Azure Blob Storage using Service Connector, with a system-assigned managed identity.
109
+
This step creates a connection between Azure Function and Azure Blob Storage using Service Connector, with a system-assigned managed identity.
110
110
111
111
Service Connector configured a `MyBlobInputConnection__serviceUri` variable in the function's app settings used by the function binding runtime to connect to the storage, so that the function can read data from the blob storage. You can learn more about [how Service Connector helps Azure Functions connect to services](./how-to-use-service-connector-in-function.md).
112
112
113
113
## Deploy your function to Azure
114
114
115
-
Now you can deploy your function to Azure and verify the storage blob input binding works.
115
+
Now you can deploy your function to Azure and verify that the storage blob input binding works.
116
116
117
117
1. Follow the [tutorial](../azure-functions/how-to-create-function-vs-code.md?pivot=programming-language-python?pivots=python-mode-configuration#deploy-the-project-to-azure) to deploy your function to Azure.
118
-
1. To verify the function can read the blob, rightclick `Execute Function Now...` on the function in the Visual Studio Code **RESOURCES** view and check the function response. The response message should contain the content in your blob file.
118
+
1. To verify the function can read the blob, right-click `Execute Function Now...` on the function in the Visual Studio Code **RESOURCES** view and check the function response. The response message should contain the content in your blob file.
119
119
120
120
## Troubleshoot
121
121
122
-
If there are any errors related with storage host, such as `No such host is known (<account-name>.blob.core.windows.net:443)`, you need to check whether the connection string you use to connect to Azure Storage contains the blob endpoint or not. If it doesn't, go to Azure Storage in the Azure portal, copy the connection string from the `Access keys`blade, and replace the values.
122
+
If there are any errors related with storage host, such as `No such host is known (<account-name>.blob.core.windows.net:443)`, you need to check whether the connection string you use to connect to Azure Storage contains the blob endpoint or not. If it doesn't, go to Azure Storage in the Azure portal, copy the connection string from the `Access keys`tab, and replace the values.
123
123
124
124
If the error happens when you start the project locally, check the `local.settings.json` file.
125
125
126
-
If the error happens when you deploy your function to cloud (in this case, Function deployment usually fails on `Syncing triggers`), check your function's App Settings.
126
+
If the error happens when you deploy your function to the cloud (in this case, function deployment usually fails on `Syncing triggers`), check your function's App Settings.
0 commit comments