Azure function not running successfully inside ADF

ash 26 Reputation points
2022-11-18T08:04:49.647+00:00

My azure function returns 404 as response code and so the function fails when running in ADF. I am using async mode to delete more than 500 entries in a single Azure table on a single partition key. Normal delete operation takes more time and thus I am using async mode. Using application insight I found this below error multiple times in a single execution.

Response status: 404 Response headers: 'Cache-Control': 'no-cache' 'Transfer-Encoding': 'chunked' 'Content-Type': 'application/json;odata=minimalmetadata;streaming=true;charset=utf-8' 'Server': 'Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0' 'x-ms-request-id': 'bde48b8f-4002-001b-3909-fb4af5000000' 'x-ms-client-request-id': '6227df30-66fc-11ed-82c7-00155d0d9b07' 'x-ms-version': 'REDACTED' 'X-Content-Type-Options': 'REDACTED' 'Date': 'Fri, 18 Nov 2022 04:49:58 GMT'

Code sample

#Import libraries  
#Followed by code to load the file from ADLS as a dataframe  
#Then the dataframe is converted into list named customer_list  

   @app.post('/Trigger_CS_deletion/')  
   async def execute_queries(dummies= None):   
    start = datetime.datetime.now()   
    await delete_data()  
    end = datetime.datetime.now()  
    time_taken = end -start  
    time_taken = str(time_taken.total_seconds())     + " seconds"  
    return {"Time taken to execute the queries" : time_taken}   


async def delete_data():  
    credential = AzureNamedKeyCredential(STORAGE_ACCOUNT_NAME, STORAGE_ACCOUNT_KEY)  
    table_client = TableClient(endpoint=STORAGE_ACCOUNT_NAME+".table.core.windows.net", table_name=TABLE_NAME, credential=credential)  
    delete_tasks = [table_client.delete_entity(partition_key=str(0), row_key=c) for c in customer_list]  
    await asyncio.wait(delete_tasks)  
    await table_client_trend.close()       

async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:  
    return func.AsgiMiddleware(app).handle(req, context)  

if __name__ == "__main__":  
    asyncio.run(main())  

Error message from ADF
![261821-image.png]1

ADF settings: where function name is the name of the function created inside my function app
261748-image.png

However, when the URL is triggered locally from browser the code works fine and gives me the following message

261719-image.png

Any advise on how to solve this ?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
3,000 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
7,140 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 54,376 Reputation points
    2022-11-21T04:47:15.73+00:00

    @ash Thanks for reaching out. As you are passing dummies query parameter when you are executing the function code and you have confirmed that it is working as expected.
    As per the screenshot of you ADF pipeline you are passing the JSON object with one of the properties as dummies but you need to pass the value as query string from your ADF pipeline to execute the function successfully. There are two ways to resolve the issue:

    • Update your function app code and get the dummies value as the request body rather than query string.
    • Update your ADF pipeline and pass the query parameter in the function name property in your ADF pipeline as below. As query string should be appended to the function name, like YourFunctionName?dummies=d. For more details, please refer to this routing and queries section. If you would like to see the query broken out as a separate input, please suggest it in the feedback forum.

    262348-image.png