Managed function in Static Web Apps cannot find module azure.mgmt

Sofia Louisy 40 Reputation points
2023-05-11T12:11:10.1333333+00:00

I am hosting a Static Web App, where I deploy manually with swa cli. I have an api that needs to connect to other resources in the same resource group. For that, I am using the python sdk. It works as expected locally, but when deployed, the function cannot locate the sdk modules.

I cannot find anything in the documentation about these modules not being supported in managed functions. I have filled up my requirements.txt with the modules I need. Am I missing a step?

Exception while executing function: Functions.list_subscriptions Result: Failure
Exception: ModuleNotFoundError: No module named 'azure.mgmt'. Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound
Stack:   File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 370, 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 48, 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 44, in call
    return func(*args, **kwargs)
  File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 132, 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/list_subscriptions/__init__.py", line 6, in <module>
    from azure.mgmt.apimanagement import ApiManagementClient
 
Azure Static Web Apps
Azure Static Web Apps
An Azure service that provides streamlined full-stack web app development.
851 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Ryan Hill 27,031 Reputation points Microsoft Employee
    2023-05-30T00:37:26.91+00:00

    @Sofia Louisy

    I spent a considerable amount of time trying to repro your issue and came up short. I wasn't able to get the tooling to work on my environment with a backend Azure Function. I did try to deploy a simple angular app with a C# function. Using CI/CD I can see the deployment occurring and the api/message endpoint returning 200. When using SWA CLI deploy command, my api did not deploy and unfortunately, I don't see any logs that would help me diagnose.

    I would advise using yaml CI/CD pipeline to deploy your SWA with API. My gut tells me that the requirements.txt is failure, but there aren't any logs to review to confirm. So switching to a CI/CD pipeline will at least afford the ability to diagnose the deployment.