Azure functions deploying fail from VS Code

Viewed 3384

I am trying to deploy my azure function (python) from VS code and it's giving the below error.

I was able to debug my code in my local machine without any error, and I am not understanding why deployment is failing.

11:55:51 PM nhtsacleanse: Detecting platforms...
11:55:51 PM nhtsacleanse: Error: Oops... An unexpected error has occurred.
11:55:53 PM nhtsacleanse: /opt/Kudu/Scripts/starter.sh oryx build /tmp/zipdeploy/extracted -o /home/site/wwwroot --platform python --platform-version 3.7 -p packagedir=.python_packages/lib/site-packages
11:55:57 PM nhtsacleanse: Deployment failed.

enter image description here

Created azure function app in azure portal

enter image description here

enter image description here

enter image description here

2 Answers

According to my experience, deploy function by clicking the button in VS code sometimes may occur unexpected error message. You can deploy your function by using command func azure functionapp publish <functionAppName> --build remote instead.

Before run the command in your VS code, you need to create a function app first on azure portal. Please choose python 3.7 like below screenshot show when you create the function app on portal(to avoid version issue) because it seems your local python function is 3.7. Then run the command in "Terminal" window of your VS code to deploy the code from local to azure. I usually use this deployment method and always works fine.

enter image description here

This was the shortest path to a solution for me. This reference:

Key Sample value AzureWebJobsStorage DefaultEndpointsProtocol=https;AccountName=...

https://docs.microsoft.com/en-us/azure/azure-functions/functions-app-settings#azurewebjobsstorage

Lead me to inspecting my azure function app configuration:

enter image description here

And seeing that the AzureWebJobsStorage was missing.

I had already created a storage account, when I tried to deploy my function previously, and evidently, the deployment step created the storage account for me, but failed to add that storage account to the function app configuration.

I retrieved the connection string from:

storage account -> access keys -> connection string

and used the value in the source value of the AzureWebJobsStoage configuration setting.

After adding that configuration, I was able to then run the following command from Visual Studio Code, with the Azure Function App workspace open:

func azure functionapp publish Text-To-Image --build remote

And received a confirmation stating:

Deployment successful. Remote build succeeded!

Related