0

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.

Marco
  • 525
  • 4
  • 17
  • Perhaps it is because `cold start` causes function 2 to wait for a certain period of time before it starts running. You can check whether there is a log message of successful execution in the monitor after a period of time. – Frank Borzage Jun 10 '21 at 00:58
  • I am not so sure if the cold start has anything to do with this behaviour. If it were, the cold start would have an impact on more than just the request made from Function1. In fact, I am running on a consumption plan, and with the built-in behaviour to pull from pre-warmed placeholder functions .. well i doubt it is the cold start. I realy think I'm doing something incorrect with the POST. However, I will try creating a second functions app to run Function2 independently. Thx Frank – Marco Jun 10 '21 at 07:09
  • Added some more info to the OP. I found that Function1 does trigger Function2 every single time; However the logging shows me some info which i find odd. See OP – Marco Jun 10 '21 at 08:03
  • Unfortunately, the same behaviour applies when function2 runs in a different function app. – Marco Jun 10 '21 at 12:56
  • Could you please check whether there is a log of successful execution of function2 in the [Monitor](https://i.stack.imgur.com/dTl3P.png), because the log in `Code+Test` is not very stable. – Frank Borzage Jun 11 '21 at 02:04
  • That's actually entirely empty. My application insights is actually showing me all trace/information logs and from what i've seen so far offers much better information. – Marco Jun 11 '21 at 07:18

0 Answers0