I have a python Funktion function_app.py
(triggered every minute) in Azure Like this
import azure.functions as func
import logging
app = func.FunctionApp()
@app.timer_trigger(schedule="0 */1 * * * *", arg_name="myTimer", run_on_startup=False,
use_monitor=False)
def zsdbi(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('09 Python timer trigger function executed.')
On the same Level in the Filesystem I have a file newconfig.py
like this :
class MyConfig:
def __init__(self, ftp_host=None, ftp_username=None, ftp_password=None,
sharepoint_url=None, sharepoint_clientid=None, sharepoint_clientsecret=None, azure=False):
self._ftp_host = ftp_host
self._ftp_username = ftp_username
self._ftp_password = ftp_password
self._sharepoint_url = sharepoint_url
self._sharepoint_clientid = sharepoint_clientid
self._sharepoint_clientsecret = sharepoint_clientsecret
When I try to import newconfig.py
in function_app.py
like this :
import azure.functions as func
import datetime
import json
import logging
import newconfig # This results in Error
app = func.FunctionApp()
@app.timer_trigger(schedule="0 */1 * * * *", arg_name="myTimer", run_on_startup=False,
use_monitor=False)
The function is not running anymore I assume caused by an error during Import. How can I add additonal python files not available in public packages to my Azure function
Edit 1
The function is deployed via github actions as :
steps:
- name: Checkout
uses: actions/checkout@v4
- name: 'Azure Login'
uses: azure/login@v2
with:
client-id: ${{ env.ARM_CLIENT_ID }}
subscription-id: ${{ env.ARM_SUBSCRIPTION_ID }}
tenant-id: ${{ env.ARM_TENANT_ID }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: 'Download Azure Function publishing profile'
env:
AZURE_SUBSCRIPTION_ID: ${{ env.ARM_SUBSCRIPTION_ID }}
FUNCTION_APP_RESOURCE_GROUP: ${{ env.ARM_RESOURCE_GROUP_NAME }}
FUNCTION_APP_NAME: fa-${{ env.APP_NAME }}
run: |
echo "FUNCTION_APP_PUB_PROFILE=$(az functionapp deployment list-publishing-profiles --subscription $AZURE_SUBSCRIPTION_ID --resource-group $FUNCTION_APP_RESOURCE_GROUP --name $FUNCTION_APP_NAME --xml)" >> $GITHUB_ENV
- name: "Deploy function"
uses: Azure/functions-action@v1
with:
app-name: fa-${{ env.APP_NAME }}
publish-profile: ${{ env.FUNCTION_APP_PUB_PROFILE }}
package: src
src
containing all python files
2
Answers
Two Screenshots showing the app-files on azure belonging to this function. It is not running (Assuming Error during import). Only If I remove
#import zsbiconfig
. I do not see any fault hereAdd
newconfig.py
in the same directory as yourfunction_app.py
.If
newconfig.py
is located in a subfolder, you will need to adjust the import path accordingly.Example: If
newconfig.py
is placed in a subfolder namedconfig
, you’ll need to import it like this:I have created a Python function with the folder structure as below:
Folder Structure:
function_app.py:
Console Output: