how to publish a python azure function with custom modules

Stefano Giostra 6 Reputation points
2021-11-10T17:12:45.173+00:00

Hi to all,
I'm deploying my first NOT "hello word" Azure function.
I wish to keep the code clean so i used to put the common code in a custom python module.
I follow this path also with "Azure Function" so i have:

<root_dir>
|_  .gitignore
|_ host.json
|_ local.settings.json
|_ requirements.txt
|_ SaveAARealTimeData
    |_ function.json
    |_ host.json
    |_ __init__.py
    |_ main.py
    |_ mylibs                      (Is the dir with the modules used by main.py)
        |_ __init__.py
        |_ azure_sql_wrp.py
        |_ my_utility.py

On the main i make the import of the methods:

...
...
from SaveAARealTimeData.mylibs.my_utility import zzzz
from SaveAARealTimeData.mylibs.azure_sql_wrp import conn_azure_sql, generate_merge_command
...
...

When i try on my pc with the command func start
all goes fine
But when i published the function and i call it, got a generic "HTTP response code 500 Internal Server Error"

I think that the command func azure functionapp publish doesn't upload my subfolder.
How can I verify if mysubdir was uploaded?

Second question I'haven't understood how I can see the function logs?

Thanks!

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 27,661 Reputation points Microsoft Employee Moderator
    2021-11-18T01:32:27.4+00:00

    Hello @Stefano Giostra , Thank you for reaching out and apologies for the delayed response here. Your folder structure is correct and you are importing the modules using absolute references and you have __init__.py in your shared code folder which is also correct as per the documentation. I tried publishing my app with a similar set-up but I did not face any issues. We might need to look need to look at the logs to debug the issue further.
    To answer your questions

    How can I verify if mysubdir was uploaded?

    When doing a func azure functionapp publish you can add a --list-included-files flag to check which files were uploaded.

    Second question I'haven't understood how I can see the function logs?

    You can go to your Function on the portal, under developer section in Code+Test you can stream any instance logs. You can also go through this documentation to enable Application insights and Live Stream logs.

    150402-screenshot-2021-11-17-173047.png

    Hope this helps! Please let me know if you have any additional questions. Thank you!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.