How to connect to Function App(Azure Functions) from Azure Synapse Studio

Mitashi Malkani 0 Reputation points
2024-11-07T05:30:40.2666667+00:00

I want to connect my function app through Synapse studio but cannot seem to figure out the configurations. Here is my function.json and function definition along with Synapse configurations. My synapse pipeline basically takes the output of the web activity and passes it to the Azure Function. Please help!

function.json

{
  "scriptFile": "function_app.py",
  "entryPoint": "function_name",
  "bindings": [
    {
      "authLevel": "function",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    }
  ]
}

function definition (function_app.py)

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

@app.route(route="artifact_http_trigger")
def function_name(req: func.HttpRequest) -> func.HttpResponse:

Synapse Studio configurations:
User's image

User's image

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
5,373 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LeelaRajeshSayana-MSFT 17,766 Reputation points Moderator
    2024-11-08T00:53:10.92+00:00

    Hi @Mitashi Malkani Greetings! Welcome to Microsoft Q&A forum. Thank you for posting this question here.

    The bindings from the web activity to the Azure function is accurate. You should take a look into the data type of the Web activity and how it is being handled in the Azure function. Here is a sample scenario I have tried out where my web activity returns a JSON object, and I pass the same to the Azure function where I access it.

    User's image

    I passed the above JSON web activity output and tied to my Azure function just the way you did and could access it from my Function App using the following code sample

    import azure.functions as func
    import logging
    import json
    
    app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)
    
    @app.route(route="lsayana")
    def lsayana(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
        name = req.params.get('name')
        req_body = req.get_json()
        if not name:
            try:            
                return func.HttpResponse(json.dumps(req_body),mimetype="application/json",status_code=200)
            except ValueError:
                pass
            else:
                name = req_body.get('name')
    
        if name:
            return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
        else:
            return func.HttpResponse(f"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized respon
    
    
    

    Here I am just sending the request body out through the response.

    If your web activity returns a data in a format other than JSON you need to handle it accordingly. Please take a look into your Azure function app invocation logs to get some additional information on why the Function App is failing.


    If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.