File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66from azure .storage .blob import BlobServiceClient
77from azure .core .exceptions import ResourceExistsError
88
9-
109app = func .FunctionApp ()
1110
12- BLOB_CONNECTION_STRING = os .getenv ('AzureWebJobsStorage' )
13- CONTAINER_NAME = "iot-data"
14-
15- blob_service_client = BlobServiceClient .from_connection_string (
16- BLOB_CONNECTION_STRING )
17- container_client = blob_service_client .get_container_client (CONTAINER_NAME )
18-
19- try :
20- container_client .create_container ()
21- except ResourceExistsError :
22- pass
23-
2411
2512@app .function_name (name = "iot_hub_trigger" )
2613@app .event_hub_message_trigger (
3118def iot_hub_trigger (event : func .EventHubEvent ):
3219
3320 try :
21+ # ---- MOVE ALL BLOB CODE INSIDE FUNCTION ----
22+ BLOB_CONNECTION_STRING = os .getenv ('AzureWebJobsStorage' )
23+ CONTAINER_NAME = "iot-data"
24+
25+ blob_service_client = BlobServiceClient .from_connection_string (
26+ BLOB_CONNECTION_STRING )
27+ container_client = blob_service_client .get_container_client (
28+ CONTAINER_NAME )
29+
30+ try :
31+ container_client .create_container ()
32+ except ResourceExistsError :
33+ pass
34+ # --------------------------------------------
35+
3436 message = event .get_body ().decode ('utf-8' )
3537 logging .info (f"Received message: { message } " )
3638
You can’t perform that action at this time.
0 commit comments