Reputation: 994
I have my functions working locally, then when I deploy them I am getting errors like :
Result: Failure Exception: ModuleNotFoundError: No module named 'azure.cosmosdb'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 284, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 42, in call raise extend_exception_message(e, message) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.8/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/home/site/wwwroot/user-add/init.py", line 4, in from azure.cosmosdb.table.tableservice import TableService
I think this looks like the Python env on the Azure side doesn't have azure as I specify on my import like so:
import logging
import azure.functions as func
import azure.cosmosdb.table
from azure.cosmosdb.table.tableservice import TableService
from azure.cosmosdb.table.models import Entity
def main(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
user_id = req.params.get('user_id')
if not user_id:
try:
req_body = req.get_json()
except ValueError:
pass
else:
user_id = req_body.get('user_id')
if user_id:
the_connection_string = "redacted"
table_service = TableService(endpoint_suffix="table.cosmos.azure.com",
connection_string=the_connection_string)
# table_service.create_table('usertable')
user = {"PartitionKey": "user",
"RowKey": user_id}
table_service.insert_entity('usertable', user)
return func.HttpResponse(f"{user_id} added to the user database")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
I don't understand what I need to do to force an equivalent pip install on their side? Which is mad as it is supposed to be serverless?
Upvotes: 0
Views: 559
Reputation: 14088
Please first make sure you have add the azure-cosmos
to the requirements.txt file.
When you deploy Python azure function to azure, it will install modules based on this file.
Upvotes: 1