Change the default folder structure in Azure Function project with Python

Viewed 805

I'd like to create a Python project using Azure Functions. When creating, files are allocated into the default layout (as recommended in documentation), so currently my project has the following structure:

root
 | - function_1
 | | - __init__.py
 | | - function.json
 | - function_2
 | | - __init__.py
 | | - function.json
 | - function_N
 | | - __init__.py
 | | - function.json
 | - src
 | | - __init__.py
 | | - logic
 | - host.json
 | - local.settings.json
 | - requirements.txt
 | - tests

The problem is that N might be relatively big (>=10), so in this way the project will become messy very quickly. I'd like the project to be of the following format, with functions being grouped into folders (eg for versioning purpose and just to keep them separately from the code):

root
 | - v0
 | | - function_1
 | | | - __init__.py
 | | | - function.json
 | | - function_N
 | | | - __init__.py
 | | | - function.json
 | - v1
 | | - function_1
 | | | - __init__.py
 | | | - function.json
 | | - function_M
 | | | - __init__.py
 | | | - function.json
 | - src
 | | - __init__.py
 | | - logic
 | - host.json
 | - local.settings.json
 | - requirements.txt
 | - tests

or something close to it, the main aim is to separate functions into separate folders.

However when I'm trying to run a project with such a layout, I get message saying that "No job functions found", or "Unable to find project root. Expecting to find one of host.json, local.settings.json in project root.", if I move host.json to functions folder.

Is there a way to configure project to work with this custom layout, so that functions are discoverable from their grouping directories?

All my functions are HttpTriggers.

I'm using Python3.9.7 and Visual Studio Code Version: 1.63.2 with Azure Functions extension for Visual Studio Code v1.6.0

1 Answers

One of the workaround I did to change the folder structure of the Azure Functions project is:

- Created the Azure Functions Project of1 Http Trigger and 1 Queue Trigger in a separate folder called QueueTriggerFuncs.

enter image description here

- When I Published this Azure Functions Project, got the same default folder structure shown in Microsoft documentation.

enter image description here

- I tried to create a folder manually in the wwwroot folder but it gave me an error called:

409 Conflict: Cannot delete directory. It is either not empty or access is not allowed. in Azure kudu

So, While publishing the project I unchecked the Run from package setting in Visual Studio Publish Profile:

enter image description here

And then published to Azure Function App.

- Going to Kudu Console (CMD) - seen the same folder structure but this time I'm able to create the folders manually without any error.

enter image description here

- Created the new folder as QueueTriggerFuncs. - Used this command to move my Queue Trigger Functions to the the specific folder created.

mv FunctionsQ QueueTriggerFuncs

its kind of format

mv FunctionFolderName DestinationFolderName

And Now this is the modified folder structure as expected:

enter image description here

Where my QueueTriggerFuncs Folder contains only specific functions like Queue Trigger related functions.

Related