How to download Azure Function (Python) .zip file?

Viewed 1316

The docs here (from 2018) say to click Download app content from the Portal to retrieve a .zip file of your Azure Function.

However, this option is grayed out for my Python function:

enter image description here

The doc goes on to provide an alternative method for retrieving a .zip file using REST API with the following url https://<function_app>.scm.azurewebsites.net/api/zip/site/wwwroot/.

Unfortunately, this downloads a download.zip file containing only the hosts.json file rather than the Function code and associated files.

enter image description here

So, how do I download my Python Function as a .zip file from either Azure Portal, REST API or the scm backend?

EDIT 1: Trying the two proposed solutions so far yield no results either.

  • AzureWebJobsStorage: No scm-deployments container available. enter image description here

  • FTPS option: No .zip file available. Only the host.json file. enter image description here

3 Answers

Update:

From your comment, you say your function app only have 'host.json' file. So you didn't deploy the azure function before? Or you deploy failed? Ftps(for premium plan and app service plan) or copy the files one by one is to get the content of the zip file. And get zip file from the 'scm-releases' container in blob storage should be a right way.

This is the structure of a python azure function. So just get all of the files can get the content of zip files. If you didn't find anything when check it on portal, I think maybe you deploy failed or never deploy the function app before? The zip file should generate in 'scm-releases' container if you deploy successful before.

Original Answer:

It seems 'Download app content' button of python azure function is unavailable now. The documentation you provided was updated on August 12, 2018, but the support of azure function for python started on August 18, 2019, so the documentation of 'Download function app files' may not be applicable. I think maybe you can submit a ticket to the official that this button is not available.

You can use ftp to get app content, but only for premium plan and app service plan:

enter image description here

If you are based on the consumption plan, you need to click in each trigger and copy the code.

enter image description here

And the files outside the trigger is in this place:

enter image description here

Finally! Figured this out.

To download the .zip file of a deployed Python Azure Function:

  • Go to https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/
  • The body will look something like:
[
    {
        "name": "20210507210231.zip",
        "size": 22920602,
        "mtime": "2021-05-07T21:03:30.9505229+00:00",
        "crtime": "2021-05-07T21:03:30.9505229+00:00",
        "mime": "application/x-zip-compressed",
        "href": "https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/20210507210231.zip",
        "path": "/home/data/SitePackages/20210507210231.zip"
    },
    {
        "name": "20210512182244.zip",
        "size": 91280954,
        "mtime": "2021-05-12T18:22:46.4017597+00:00",
        "crtime": "2021-05-12T18:22:46.4017597+00:00",
        "mime": "application/x-zip-compressed",
        "href": "https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/20210512182244.zip",
        "path": "/home/data/SitePackages/20210512182244.zip"
    },
    {
        "name": "20210520163007.zip",
        "size": 22248931,
        "mtime": "2021-05-20T16:31:13.4771898+00:00",
        "crtime": "2021-05-20T16:31:13.4771898+00:00",
        "mime": "application/x-zip-compressed",
        "href": "https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/20210520163007.zip",
        "path": "/home/data/SitePackages/20210520163007.zip"
    },
    {
        "name": "packagename.txt",
        "size": 18,
        "mtime": "2021-05-20T16:31:20.8453653+00:00",
        "crtime": "2021-05-20T16:31:20.8453653+00:00",
        "mime": "text/plain",
        "href": "https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/packagename.txt",
        "path": "/home/data/SitePackages/packagename.txt"
    },
    {
        "name": "packagepath.txt",
        "size": 23,
        "mtime": "2021-05-12T18:22:46.5567703+00:00",
        "crtime": "2021-05-12T18:22:46.5567703+00:00",
        "mime": "text/plain",
        "href": "https://<function-app-name>.scm.azurewebsites.net/api/vfs/data/SitePackages/packagepath.txt",
        "path": "/home/data/SitePackages/packagepath.txt"
    }
]
  • Go to the href URL shown with the latest mtime to download the file
  • Notice: The latest timestamp is lower in the list (at least for me)

Its documented here

If you have access to the Function's storage account then just download from scm-releases container.

You can find the account connection string in AzureWebJobsStorage parameter under Configuration in portal (App Settings).

enter image description here

Related