Azure Function triggering http Azure Function

957 Views Asked by At

I have currently written this piece of code for one of my functions:

FUNCTION_URL = "https://functionapp.azurewebsites.net/api/functionname?code={function_key_secret}"
FUNCTION_URL_PAYLOAD = "&name={name}&number={number}"

def trigger_function(name, number):
    function_key_secret = get_keyvault_secret(secret_item_name='function-key')
    url = FUNCTION_URL.format(function_key_secret=function_key_secret)
    payload = FUNCTION_URL_PAYLOAD.format(name=name,number=number)
    try:
        azure_response = requests.request(method='POST', url=f"{url}{payload}")
    except requests.exceptions.RequestException as error:
        logging.error(
            'Failed to make POST to the Function: %s', error)

I am using this method to trigger a second Azure Function which is set up to trigger on HTTP request. However, I don't think it is working. The HTTP triggered Function is not showing any Successful execution count, while the Successful execution count on the initial Function is going up. I can also see in the logging that the initial function is working properly.

For the scenario: Function1 = Updates cosmosdb table & triggers Function2 Function2 (HTTP Trigger) = Uses input (name and number) from Function1 to send data to a service outside of Azure.

I can trigger function2 manually, and in the logging I will see that it works. Yet when Function1 executes the above code, I do not see the same logs appearing. Don't mind the get_keyvault_secret method. I use it inside Function1 also and it works perfect. There are no errors in my log output by the way.

Function.json:

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

The logging shows me this however whenever Function2 is triggered from Function1. This is the log output from Function1:

2021-06-10T07:58:17Z   [Information]   ManagedIdentityCredential will use App Service managed identity
2021-06-10T07:58:17Z   [Information]   Request URL: 'http://localhost:8081/msi/token?api-version=REDACTED&resource=REDACTED'
2021-06-10T07:58:17Z   [Information]   Request method: 'GET'
2021-06-10T07:58:17Z   [Information]   Request headers:
2021-06-10T07:58:17Z   [Information]       'secret': 'REDACTED'
2021-06-10T07:58:17Z   [Information]       'User-Agent': 'azsdk-python-identity/1.6.0 Python/3.7.10 (Linux-5.4.81-microsoft-standard-x86_64-with-debian-10.9)'
2021-06-10T07:58:17Z   [Information]   No body was attached to the request
2021-06-10T07:58:17Z   [Information]   Response status: 200
2021-06-10T07:58:17Z   [Information]   Response headers:
2021-06-10T07:58:17Z   [Information]       'Date': 'Thu, 10 Jun 2021 07:58:16 GMT'
2021-06-10T07:58:21Z   [Information]   Executing 'Functions.EventHubTrigger' (Reason='(null)', Id=9b5e6c36-6227-45b1-9bd0-151f22aac147)
2021-06-10T07:58:21Z   [Information]   Trigger Details: PartionId: 0, Offset: 51570324760-51570324760, EnqueueTimeUtc: 2021-06-10T07:58:21.3150000Z-2021-06-10T07:58:21.3150000Z, SequenceNumber: 107798-107798, Count: 1

It's going to localhost, so should I change the URL to be one sent to localhost? While I'm getting a 200 statuscode response. The logging on Function2 doesnt show me any request got successfully handled. It's literally empty. When I do a manual request towards Function2 I can see a log like this:

2021-06-10T07:49:15Z   [Information]   Python HTTP trigger function processed a request.
2021-06-10T07:49:15Z   [Information]   The request body contained name & number
2021-06-10T07:49:17Z   [Information]   Response status: 200

EDIT (14-6-2021): I have moved on from using a HTTP triggered function for Function2, to it being eventhub triggered. But the issue still remains after me trying to get it to work for 2 days browsing through any blog/forum I could find.

0

There are 0 best solutions below