skip to Main Content

I am completely new to Azure cloud. When I deployed my Azure Function in to Function app using VS code, in the Azure portal, I am seeing the error says that "System.InvalidOperationException : A collision for Host ID ‘functionAppName’ was detected in the configured storage account."

When I try to run the function using the option Code Test/Run, the Run button is disabled with the error message "Running your function in portal requires the app to explicitly accept requests from https://portal.azure.com. This is known as cross-origin resource sharing (CORS)."

I have no idea of what these errors all about and how to fix these errors, since working with Azure is completely new to me.

Kindly help to fix these issues and make the function work properly.

Error 1:

AZFD004
Diagnostic event
Error code
AZFD004
Level
Error
Message
A collision for Host ID 'functionAppName' was detected in the configured storage account. For more information, see URL.
Details
System.InvalidOperationException : A collision for Host ID 'functionAppName' was detected in the configured storage account. For more information, see URL.
Hit count
23
Timestamp
October 6, 2023 at 12:30:18 AM GMT+5:30
Help link

Error 2:

Running your function in portal requires the app to explicitly accept requests from https://portal.azure.com. This is known as cross-origin resource sharing (CORS). Click here to add https://portal.azure.com to the allowed origin configuration.

__init__.py:

import azure.functions as func
import sys
import os
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_dir))

 # import 'test_run' module
from test_run import func_1, func_2, func_3

def main(req: func.HttpRequest) -> func.HttpResponse:
    try:
        func_1()  
        func_2()
        func_3()

        name = req.params.get('name')
        if not name:
            return func.HttpResponse("Please pass a 'name' parameter in the query string.", status_code=400)

        return func.HttpResponse(f"Hello {name}. The function triggered successfully.")
    except Exception as e:
        return func.HttpResponse(f"An error occurred: {str(e)}", status_code=500)

test_run.py:

def func_1():
    '''some code here'''
def func_2():
    '''some code here'''
def func_3():
    '''some code here

2

Answers


  1. Error 1

    I’m assuming you haven’t redacted the above error message and it’s verbatim saying A collision for Host ID 'functionAppName' was detected in the configured storage account. For more information, see URL.? I’d be very surprised if your Function App is actually called functionAppName since Function App names must be globally unique, so I’d say it looks like you’ve got a copy + paste error somewhere in your configuration. Do something like a git grep -i 'functionAppName' to search for all instances of the string functionAppName in your repo and replace them with the actual name of the Function App.

    Error 2

    I’m not quite sure what the question is here? The error message is telling you that you need to add https://portal.azure.com/ to the list of allowed origins in the CORS setting for your Function App. For more info on how to do this this refer to the following MS Docs: Cross-origin resource sharing.

    Login or Signup to reply.
  2. I have used your code and test it locally as well as in portal post deployment, it worked as expected for me.

    Code:

    import  sys
    import  os
    import  azure.functions  as  func 
    from .test_run  import  func_1,func_2,func_3 
    
    current_dir  =  os.path.dirname(os.path.abspath(__file__))
    sys.path.append(os.path.join(current_dir))
    
    def  main(req: func.HttpRequest) -> func.HttpResponse:
    
    try:
    func_1()
    func_2()
    func_3()  
    
    name  =  req.params.get('name')
    if  not  name:
        return  func.HttpResponse("Please pass a 'name' parameter in the query string.", status_code=400)
    return  func.HttpResponse(f"Hello {name}. The function triggered successfully.")
    
    except  Exception  as  e:
    return  func.HttpResponse(f"An error occurred: {str(e)}", status_code=500)
    

    test_run.py-

    def  func_1():
    print("Testing func_1")
    
    def  func_2():
    print("Testing func_2")
    
    def  func_3():
    print("Testing func_3")
    

    Local Test Result-

    While testing, you need pass name=<anything> in order to get the result.

    enter image description here

    enter image description here

    In Portal-

    You need to pass the name parameter like below.

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search