1

I am going to be using the test function that VS-code azure extension auto creates as a "simple" case for this problem.

I can add any modules (pandas, requests, facebook) in requirements.txt and it works fine. However when I add google-cloud-storage, my function breaks and only returns 500.

I should note it only breaks when testing on Azure, when run locally it works fine

Also, if the function is created in the Azure Portal (rather than connecting to Github) and google-cloud-storage is pip installed using ssh, then the function also works fine.

It seems to be when VS-code is being used to deploy the function with 'google-cloud-storage' in requirements.txt that we get problems. Anyway, thats what I've found, any help would be appreciated

**How to reproduce: ** **Step 1: **Created Function App

This function App uses: App Service Plan, Basic B1 (100 total ACU, 1.75 GB memory, 1 vCPU) enter image description here Can only do Linux as windows isnt supported when selecting python

**Step 2: **The default function is created with VS-code azure extension https://i.stack.imgur.com/XBLpV.png

The function looks like this enter image description here

Step3: I now add this to my github repository and which then gets picked up by the Azure App service to deploy as a function. Using the function app is connected to the repo enter image description here

We have success without google-cloud-storage in requirements.txt enter image description here

Now we add google-cloud-storage: enter image description here we then git push this to our repo and Azure creates our deployment

When we try to test the function now, we get consistent 500 results with no logs. enter image description here

I want to continue to using the Git-hub approach, so a solution where we keep the same process would be great but any advice will be amazing. Thanks in advance guys.

Tried pip installing google-cloud-storage manually using ssh and then deploying with VS-code, that broke that whole function app.

1 Answers1

1

I have added google-cloud-storage in my requirements.txt and my azure function Http repository is in the folder structure like below:-

Init.py and function.json are inside HttpTrigger folder and rest all the files are outside it in the root directory, Including requirements.txt:-

enter image description here

Now, I created Azure Function app with Functions Premium plan and selected Python 3.10:-

enter image description here

After my function app Deployment, I went to Deployment Center and connected my Function to the github repository above and started the github workflow:-

enter image description here

My Github workflow:-

You can find my Github workflow from here

name: Build and deploy Python project to Azure Function App - siliconfunc1

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
  PYTHON_VERSION: '3.10' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Setup Python version
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      - name: Install dependencies
        run: pip install -r requirements.txt
        
      # Optional: Add step to run tests here

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-function.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'siliconfunc1'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D29DD8E1DA1B41A68C550903EEF23B74 }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

Output:-

The HttpTrigger got deployed successfully, and when I ran the function I received the same error code as yours. But when I checked the Logs I saw an error related to protobuf package that was restricting Azure Function HttpTrigger from running successfully, Refer below:-

Error:-

enter image description here

2023-06-15T08:21:20.763 [Error] TypeError: Descriptors cannot not be created directly.
2023-06-15T08:21:20.826 [Information] If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
2023-06-15T08:21:20.827 [Information] If you cannot immediately regenerate your protos, some other possible workarounds are:
2023-06-15T08:21:20.827 [Information] 1. Downgrade the protobuf package to 3.20.x or lower.
2023-06-15T08:21:20.827 [Information] 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

I referred this SO thread answer by Kushan Gunasekara and added protobuf==3.20. along with google-cloud-storage in my requirements.txt and ran the deployment again, And after the HttpTrigger was deployed it ran successfully, Refer below:-*

My updated requirements.txt:-

azure-functions
protobuf==3.20.*
google-cloud-storage

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

SiddheshDesai
  • 3,668
  • 1
  • 2
  • 11
  • Very nice, thank you Siddesh- adding the downgrade for protobuf makes the function work now... I wonder why I couldn't see that error in the logs....maybe has to be a premium function app – Marsel Gokovi Jun 16 '23 at 00:03