I have created a function app in Azure. Using Visual Studio Code, I created a function in local, and deployed it to existing function app.
The first time I deployed, it was successful.
The second time, however, when I deployed the same function from local to the same existing function app, the http_trigger
inside the function app disappeared.
After that, I tried the deployment multiple times, but still the http_trigger
is not found.
Why did it get removed on the second deployment? Should I deploy the function only once?
If yes, is there any way to perform the deployment again, in case of any changes in the code inside the function?
I have the script file test_run.py
with some code, inside the function in the function_app.py
file, I tried to import my script file like below, after making these changes, I tried for deployment when the http_trigger
got removed.
function_app.py
:
import test_run
rest of the default trigger function code
if name:
test_run.main()
return f"Hello {name}. The function triggered"
else:
test_run.main()
return f"Hello. The function triggered without a name"
test_run.py
:
def func_1():
function code
def func_2():
function code
def func_3():
function code
def main ():
try:
func_1()
func_2()
func_3()
except:
code for retry
I was also not able to create only the http_trigger
inside the function, that option is not available for me in either vs code or in Azure Portal.
Also, if I create the new function and function app from scratch, it was deployed the first time successfully. When I do some changes in the script and try to deploy it again, the http_trigger
got removed.
Please help me to resolve this.
There might be an issue with the VS code extension while which is causing your function app to not deploy again after you make the code changes. Ideally if you deploy your local trigger multiple times, It will get deployed with the new code successfully in the Function app in portal.
As a workaround, Make sure you have Function core tools installed and use the below commands in your VS code to deploy the Function multiple times in the Function app like below:-
az login
az account set --subscription "Subscription name"
func azure functionapp publish functionappname
I also made some changes to your code and used sys.path method to import the test_run.py file in my code like below:-
init.py:-
import azure.functions as func
import sys
import os
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_dir))
# import 'test_run' module
from test_run import func_1, func_2, func_3
def main(req: func.HttpRequest) -> func.HttpResponse:
try:
func_1()
func_2()
func_3()
name = req.params.get('name')
if not name:
return func.HttpResponse("Please pass a 'name' parameter in the query string.", status_code=400)
return func.HttpResponse(f"Hello {name}. The function triggered successfully.")
except Exception as e:
return func.HttpResponse(f"An error occurred: {str(e)}", status_code=500)