Search code examples
pythonazureazure-functions

Azure Portal function app not showing functions after deploy from VS Code


I have, for example, this function

enter image description here

I deployed it with VS Code using the following F1 option in VS Code enter image description here

Nonetheless, when I go to the function app portal, it shows nothing under the functions submenu: enter image description here

I don't know why I am not being able to see my functions in my function app, what am I missing?

Here is the dummy code of the function:

import azure.functions as func
import logging
import pymssql
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from datetime import datetime, timedelta
import json
import jwt

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)

@app.route(
    route="actualizar_contrasena", methods=["POST"], auth_level=func.AuthLevel.ANONYMOUS
)
def actualizar_contrasena(req: func.HttpRequest) -> func.HttpResponse:
   
    try:
        # Establece la conexión
        conn = pymssql.connect(X, XX, XXX, XXXX)
        cursor = conn.cursor()
        email = auth_token.get("email")
        
        if email and password:
            # do things
        else:
            return func.HttpResponse(f"Error", status_code=500)

    except Exception as e:
        logging.error(f"Error: {e}")
        return func.HttpResponse(f"Error: {e}", status_code=500)
    finally:
        if "conn" in locals() and conn:
            conn.close()

    return func.HttpResponse(
        "Elemento eliminado correctamente",
        status_code=200,
    )

UPDATE

After following @RithwikBoj instructions, I'm in the same situation. I have observed that locally I can't see the functions neither:

enter image description here

This is my host.json:

{
  "version": "2.0",
  "extensions": {
    "http": {
      "routePrefix": ""
    }
  },
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

And this is my structure:

root
|_.venv
|_.funcignore
|_host.json
|_function_app.py
|_ local.settings.json
|_gets
   |__ __init__.py
   |__  function_app.py
   |__  function.json

Solution

  • I have used below code and it got deployed for me and followed below process:

    function_app.py:

    import azure.functions as func
    import logging as ri_lg
    import pymssql as chop
    from azure.identity import DefaultAzureCredential
    from azure.keyvault.secrets import SecretClient
    
    rith = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
    
    @rith.route(
        route="rith_func", methods=["POST"], auth_level=func.AuthLevel.ANONYMOUS
    )
    def rith_func(req: func.HttpRequest) -> func.HttpResponse:
        try:
            rith_rq_bdy = req.get_json()
            eml = rith_rq_bdy.get("email")
            pwd = rith_rq_bdy.get("password")
            ri_con = chop.connect(server="rithwik.database.windows.net",user="rithwik",password="RTestpass@2",database="test1")
            cho_cur = ri_con.cursor()
            cho_cur.execute("UPDATE users SET password = %s WHERE email = %s",(pwd, eml))
            ri_con.commit()
    
            return func.HttpResponse("Hello Rithwik, the Password has been updated",status_code=200)
    
        except Exception as f:
            ri_lg.error(f"Error: {f}")
            return func.HttpResponse(f"Hello Rithwik, there is an error: {f}",status_code=500)
        finally:
            if "ri_con" in locals() and ri_con:
                ri_con.close()
    

    local.settings.json:

    {
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "python",
        "AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
      }
    }
    

    requirements.txt:

    azure-functions
    pymssql
    azure-identity
    azure-keyvault-secrets
    

    host.json:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "excludedTypes": "Request"
          }
        }
      },
      "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[4.*, 5.0.0)"
      }
    }
    

    Structure:

    RithAppFolder
    ├── __ pycache __
    ├── .venv
    ├── .vscode
    ├── .funcignore
    ├── .gitignore
    ├── function_app.py
    ├── host.json
    ├── local.settings.json
    └── requirements.txt
    

    Output:

    Deployed from VS Code:

    enter image description here

    After Deployment:

    enter image description here

    Then tested with wrong data to get 500 error:

    enter image description here

    Make sure to add all the packages.