I have JSON documents being uploaded into an Azure Blob Container and I have written an Azure Python Function to write the JSON into CosmosDB. The triggering works fine, but I get an error. Here is the Python function:
import logging
import azure.functions as func
def main(myblob: func.InputStream, doc: func.Out[func.Document]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
json_data = myblob.read()
try:
# Store output data using Cosmos DB output binding
doc.set(func.Document.from_json(json_data))
except Exception as e:
logging.info(f"Error: {e}")
print('Error:')
print(e)
Here is the function.json file:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "cloud-save-blob-container/{name}",
"connection": "cloudsavestorage_STORAGE"
},
{
"type": "cosmosDB",
"name": "userJson",
"databaseName": "ToDoList",
"collectionName": "Items",
"createIfNotExists": false,
"connectionStringSetting": "MyCosmosDBConnectionString",
"direction": "out"
}
],
"disabled": false
}
This the error I see in the Azure Portal:
Result: Failure Exception: FunctionLoadError: cannot load the JsonBlobTrigger1 function: the following parameters are declared in Python but not in function.json: {'doc'} Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 290, in _handle__function_load_request self._functions.add_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/functions.py", line 112, in add_function raise FunctionLoadError(
Thanks for assistance.