0

I want to deploy a easy function to Azure. When i deploy with this code it's ok :

import azure.functions as func

@app = func.FunctionApp()
@app.function_name(name="echo")
@app.route(route="echo")
def echo_function(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("Echo OK")

I see in Azure Portal my function echo.

But when i add a new function to my function_app.py i don't see any function :

import azure.functions as func
from azure.storage.blob import ContainerClient
from azure.identity import ManagedIdentityCredential


@app.function_name(name="Logging")
@app.route(route="Logging")
def logging_function(req: func.HttpRequest) -> func.HttpResponse:
    credential = ManagedIdentityCredential()
    container_client = ContainerClient(account_url="https://sae2sbxfchpv00002.blob.core.windows.net",
                        container_name="f03temp",
                        credential=credential)
container_client.delete_container()

return func.HttpResponse(f"Blob", status_code=200)

My function app have a managed Identity enabled. I have a container name "f03temp" in my storage account. My fonction app have the "Data Storage contributor" acess for the storage account. In vs code i have all the librairies neccesary.

I can't test in local, because i don't have blob acess with my account.

Anyone can help me for understand? Thanks in advance

I want to see my function in Azure Portail after the deployment.

1 Answer 1

1
import azure.functions as func
from azure.storage.blob import ContainerClient
from azure.identity import ManagedIdentityCredential

app = func.FunctionApp()

@app.function_name(name="echo")
@app.route(route="echo")
def echo_function(req: func.HttpRequest) -> func.HttpResponse:
    return func.HttpResponse("Echo OK")

@app.function_name(name="Logging")
@app.route(route="Logging")
def logging_function(req: func.HttpRequest) -> func.HttpResponse:
    try:
        credential = ManagedIdentityCredential()
        container_client = ContainerClient(
            account_url="https://sae2sbxfchpv00002.blob.core.windows.net",
            container_name="f03temp",
            credential=credential
        )
    
        container_client.delete_container()
        return func.HttpResponse("Container deleted successfully", status_code=200)
    
    except Exception as e:
        return func.HttpResponse(f"Error: {str(e)}", status_code=500)

Missing app initialization: You had @app but never created the app instance. Should be app = func.FunctionApp()
Code outside function scope: The container client operations were outside the function, which causes deployment issues. All Azure operations must be inside the function.
No error handling: Azure operations can fail, so proper error handling is essential.
Missing try-catch: Container operations should be wrapped in exception handling.

Test locally by using Azure CLI authentication:

az login

Verify permissions: Ensure your Function App's managed identity has "Storage Blob Data Contributor" role on the storage account.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, Thank you for your response. I made the change you mentioned. When I'm connected with the Azure CLI and I publish the code folder using: func azure functionapp publish fahpvs00001api --no-build I still encounter the same issue. If I only include the "echo" function in the code, it works — I can see it in Azure. But when I add the "Logging" function, I don't see either function in the Azure portal. In Azure, I can confirm that the files host.json, requirements.txt, and function_app.py are updated. But the result is the same. I don't understand why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.