DEV Community

Simon Waight
Simon Waight

Posted on • Originally published at blog.siliconvalve.com on

Deploy Python-based Azure Functions using Azure DevOps

In August Microsoft announced that Python support in Azure Functions was Generally Available (GA), meaning it was ready for use for production scenarios.

In this post I'll take a quick look at how you can quickly deploy Python Functions using Azure Pipelines which is a part of Azure DevOps.

Build and package

You now have the choice to package Python Azure Functions using a pre-built template in Azure Pipelines.

Python Functions Build Template

Once you select this you will have all you need to restore any Python modules you have in your requirements.txt file and ensure any Azure Function Extensions are also installed. The resulting footprint is then zipped for use in a release.

If, like me, you put multiple independent Azure Functions into a single Azure Git Repo then you will need to modify three of the build Tasks to ensure you have the sub-folder selected when running commands.

First we need to ensure we restore the Azure Functions Extensions so we'll add a 'cd' command in and switch into the right folder.

Extensions subfolder

Then we have make sure we restore Python modules based on the requirements.txt in the subfolder.

Subfolder for requirements.txt

Finally we need to edit the Archive Files Task ensure you select the same sub-folder as the previous step.

Right, if you run this build you'll end up with a zip file ready to deploy.

Releasing into Azure

We can now create an Azure Pipelines Release that uses the standard Azure Function template (shown below). There are no special steps to use as you are deploying into a host environment already setup for Python Functions.

Release Template

Once you run the Release your Function is deployed! If you need to deploy App Settings at the same time you can use the 'Application and Configuration Settings' section of the 'Deploy Azure Function App' Task to specify the settings to deploy.

That's it - so much easier than when this capability was all in preview!

Top comments (1)

Collapse
 
frankshih profile image
frankShih

Hi,
Thanks for your sharing.

I try to follow your steps, and at the "release" section I encounter the error below:

##[error]Error: Failed to get resource ID for resource type 'Microsoft.Web/Sites' and resource name 'az-func-sample'. Error: connect ENETUNREACH 169.254.169.254:80

My Azure Function is "consumption plan"

Any suggestion would be appreciated.