Skip to content

Commit 5e161e1

Browse files
authored
Changing azurewebjobsstorage to generic name.
1 parent 2408398 commit 5e161e1

File tree

1 file changed

+52
-62
lines changed

1 file changed

+52
-62
lines changed

articles/azure-functions/functions-reference-python.md

Lines changed: 52 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ For example, the following code demonstrates the difference between the two inpu
334334
"direction": "in",
335335
"type": "blob",
336336
"path": "samples/{id}",
337-
"connection": "AzureWebJobsStorage"
337+
"connection": "STORAGE_CONNECTION_STRING"
338338
}
339339
]
340340
}
@@ -346,6 +346,7 @@ For example, the following code demonstrates the difference between the two inpu
346346
"IsEncrypted": false,
347347
"Values": {
348348
"FUNCTIONS_WORKER_RUNTIME": "python",
349+
"STORAGE_CONNECTION_STRING": "<AZURE_STORAGE_CONNECTION_STRING>",
349350
"AzureWebJobsStorage": "<azure-storage-connection-string>"
350351
}
351352
}
@@ -356,14 +357,11 @@ For example, the following code demonstrates the difference between the two inpu
356357
import azure.functions as func
357358
import logging
358359

359-
360-
def main(req: func.HttpRequest,
361-
obj: func.InputStream):
362-
360+
def main(req: func.HttpRequest, obj: func.InputStream):
363361
logging.info(f'Python HTTP-triggered function processed: {obj.read()}')
364362
```
365363

366-
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage account based on the _ID_ in the route URL and made available as `obj` in the function body. Here, the specified storage account is the connection string that's found in the `AzureWebJobsStorage` app setting, which is the same storage account that's used by the function app.
364+
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage account based on the _ID_ in the route URL and made available as `obj` in the function body. Here, the specified storage account is the connection string that's found in the `CONNECTION_STRING` app setting.
367365
::: zone-end
368366
::: zone pivot="python-mode-decorators"
369367
Inputs are divided into two categories in Azure Functions: trigger input and other input. Although they're defined using different decorators, their usage is similar in Python code. Connection strings or secrets for trigger and input sources map to values in the *local.settings.json* file when they're running locally, and they map to the application settings when they're running in Azure.
@@ -376,6 +374,7 @@ As an example, the following code demonstrates how to define a Blob Storage inpu
376374
"IsEncrypted": false,
377375
"Values": {
378376
"FUNCTIONS_WORKER_RUNTIME": "python",
377+
"STORAGE_CONNECTION_STRING": "<AZURE_STORAGE_CONNECTION_STRING>",
379378
"AzureWebJobsStorage": "<azure-storage-connection-string>",
380379
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
381380
}
@@ -390,13 +389,13 @@ import logging
390389
app = func.FunctionApp()
391390

392391
@app.route(route="req")
393-
@app.read_blob(arg_name="obj", path="samples/{id}", connection="AzureWebJobsStorage")
394-
def main(req: func.HttpRequest,
395-
obj: func.InputStream):
392+
@app.read_blob(arg_name="obj", path="samples/{id}",
393+
connection="STORAGE_CONNECTION_STRING")
394+
def main(req: func.HttpRequest, obj: func.InputStream):
396395
logging.info(f'Python HTTP-triggered function processed: {obj.read()}')
397396
```
398397

399-
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage account based on the _ID_ in the route URL and made available as `obj` in the function body. Here, the specified storage account is the connection string that's found in the AzureWebJobsStorage app setting, which is the same storage account that's used by the function app.
398+
When the function is invoked, the HTTP request is passed to the function as `req`. An entry will be retrieved from the Azure Blob Storage account based on the _ID_ in the route URL and made available as `obj` in the function body. Here, the specified storage account is the connection string that's found in the `STORAGE_CONNECTION_STRING` app setting.
400399
::: zone-end
401400

402401
For data intensive binding operations, you may want to use a separate storage account. For more information, see [Storage account guidance](storage-considerations.md#storage-account-guidance).
@@ -443,7 +442,7 @@ To produce multiple outputs, use the `set()` method provided by the [`azure.func
443442
"direction": "out",
444443
"type": "queue",
445444
"queueName": "outqueue",
446-
"connection": "AzureWebJobsStorage"
445+
"connection": "STORAGE_CONNECTION_STRING"
447446
},
448447
{
449448
"name": "$return",
@@ -457,7 +456,6 @@ To produce multiple outputs, use the `set()` method provided by the [`azure.func
457456
```python
458457
import azure.functions as func
459458

460-
461459
def main(req: func.HttpRequest,
462460
msg: func.Out[func.QueueMessage]) -> str:
463461

@@ -479,7 +477,7 @@ import azure.functions as func
479477
app = func.FunctionApp()
480478

481479
@app.write_blob(arg_name="msg", path="output-container/{name}",
482-
connection="AzureWebJobsStorage")
480+
connection="CONNECTION_STRING")
483481
def test_function(req: func.HttpRequest,
484482
msg: func.Out[str]) -> str:
485483

@@ -882,13 +880,13 @@ The following example uses `os.environ["myAppSetting"]` to get the [application
882880
```python
883881
import logging
884882
import os
883+
885884
import azure.functions as func
886885

887886
def main(req: func.HttpRequest) -> func.HttpResponse:
888-
889-
# Get the setting named 'myAppSetting'
890-
my_app_setting_value = os.environ["myAppSetting"]
891-
logging.info(f'My app setting value:{my_app_setting_value}')
887+
# Get the setting named 'myAppSetting'
888+
my_app_setting_value = os.environ["myAppSetting"]
889+
logging.info(f'My app setting value:{my_app_setting_value}')
892890
```
893891

894892
For local development, application settings are [maintained in the *local.settings.json* file](functions-develop-local.md#local-settings-file).
@@ -909,18 +907,17 @@ The following example uses `os.environ["myAppSetting"]` to get the [application
909907
```python
910908
import logging
911909
import os
910+
912911
import azure.functions as func
913912

914913
app = func.FunctionApp()
915914

916915
@app.function_name(name="HttpTrigger1")
917916
@app.route(route="req")
918917
def main(req: func.HttpRequest) -> func.HttpResponse:
919-
920-
921-
# Get the setting named 'myAppSetting'
922-
my_app_setting_value = os.environ["myAppSetting"]
923-
logging.info(f'My app setting value:{my_app_setting_value}')
918+
# Get the setting named 'myAppSetting'
919+
my_app_setting_value = os.environ["myAppSetting"]
920+
logging.info(f'My app setting value:{my_app_setting_value}')
924921
```
925922

926923
For local development, application settings are [maintained in the *local.settings.json* file](functions-develop-local.md#local-settings-file).
@@ -1086,14 +1083,14 @@ from shared_code import my_second_helper_function
10861083
# Define an HTTP trigger that accepts the ?value=<int> query parameter
10871084
# Double the value and return the result in HttpResponse
10881085
def main(req: func.HttpRequest) -> func.HttpResponse:
1089-
logging.info('Executing my_second_function.')
1086+
logging.info('Executing my_second_function.')
10901087

1091-
initial_value: int = int(req.params.get('value'))
1092-
doubled_value: int = my_second_helper_function.double(initial_value)
1088+
initial_value: int = int(req.params.get('value'))
1089+
doubled_value: int = my_second_helper_function.double(initial_value)
10931090

1094-
return func.HttpResponse(
1095-
body=f"{initial_value} * 2 = {doubled_value}",
1096-
status_code=200
1091+
return func.HttpResponse(
1092+
body=f"{initial_value} * 2 = {doubled_value}",
1093+
status_code=200
10971094
)
10981095
```
10991096

@@ -1119,22 +1116,17 @@ import azure.functions as func
11191116
from my_second_function import main
11201117

11211118
class TestFunction(unittest.TestCase):
1122-
def test_my_second_function(self):
1123-
# Construct a mock HTTP request.
1124-
req = func.HttpRequest(
1125-
method='GET',
1126-
body=None,
1127-
url='/api/my_second_function',
1128-
params={'value': '21'})
1129-
1130-
# Call the function.
1131-
resp = main(req)
1132-
1133-
# Check the output.
1134-
self.assertEqual(
1135-
resp.get_body(),
1136-
b'21 * 2 = 42',
1137-
)
1119+
def test_my_second_function(self):
1120+
# Construct a mock HTTP request.
1121+
req = func.HttpRequest(method='GET',
1122+
body=None,
1123+
url='/api/my_second_function',
1124+
params={'value': '21'})
1125+
# Call the function.
1126+
resp = main(req)
1127+
1128+
# Check the output.
1129+
self.assertEqual(resp.get_body(), b'21 * 2 = 42',)
11381130
```
11391131

11401132
Inside your *.venv* Python virtual environment folder, install your favorite Python test framework, such as `pip install pytest`. Then run `pytest tests` to check the test result.
@@ -1188,27 +1180,24 @@ You can start writing test cases for your HTTP trigger.
11881180
# <project_root>/tests/test_my_second_function.py
11891181
import unittest
11901182
import azure.functions as func
1191-
from function_app import main
11921183

1184+
from function_app import main
11931185

11941186
class TestFunction(unittest.TestCase):
1195-
def test_my_second_function(self):
1196-
# Construct a mock HTTP request.
1197-
req = func.HttpRequest(
1198-
method='GET',
1199-
body=None,
1200-
url='/api/my_second_function',
1201-
params={'value': '21'})
1202-
1203-
# Call the function.
1204-
func_call = main.build().get_user_function()
1205-
resp = func_call(req)
1206-
1207-
# Check the output.
1208-
self.assertEqual(
1209-
resp.get_body(),
1210-
b'21 * 2 = 42',
1211-
)
1187+
def test_my_second_function(self):
1188+
# Construct a mock HTTP request.
1189+
req = func.HttpRequest(method='GET',
1190+
body=None,
1191+
url='/api/my_second_function',
1192+
params={'value': '21'})
1193+
# Call the function.
1194+
func_call = main.build().get_user_function()
1195+
resp = func_call(req)
1196+
# Check the output.
1197+
self.assertEqual(
1198+
resp.get_body(),
1199+
b'21 * 2 = 42',
1200+
)
12121201
```
12131202

12141203
Inside your *.venv* Python virtual environment folder, install your favorite Python test framework, such as `pip install pytest`. Then run `pytest tests` to check the test result.
@@ -1228,6 +1217,7 @@ The following example creates a named temporary file in the temporary directory
12281217
import logging
12291218
import azure.functions as func
12301219
import tempfile
1220+
12311221
from os import listdir
12321222

12331223
#---

0 commit comments

Comments
 (0)