Loading...

Analyze HAR trace when importing Function App into API Management

Analyze HAR trace when importing Function App into API Management

Background introduction

API Management allow us to import a function app as an API, the UI offers a straightforward process to import the function app as described on this Microsoft public document. However, in this article we want to go beyond and explore what actions are performed in the background, it will allow us to understand the import process better and will help us dealing with issues while importing the function app.

 

 

Steps

Please review all the steps carefully, they are executed in the following order.

Note: The easiest way to see these steps is collecting a HAR trace.
 

1- It first sends a HEAD request to Microsoft.ApiManagement provider to confirm if the API exists in APIM, (of course it returns a 404 Not Found error which is expected because the API does not exist yet), we are just about to create it.

Didieroc_0-1685031648935.png

 

2- Then it sends a PUT request to Microsoft.ApiManagement and starts creating an empty (without operations) API in APIM.

Didieroc_1-1685031648939.png

 

Didieroc_2-1685031648942.png

 

3- Then it sends a GET request to Microsoft.Web provider trying to list all the HTTP triggers that we have in the function app.

Didieroc_3-1685031648952.png

 

4- Then it sends a POST request to Microsoft.Web provider to list the function app keys.

Didieroc_4-1685031648958.png

 

5- Then it sends a PUT request to Microsoft.Web provider to create a new Host key in the Function app, with the name apim-{your Azure API Management service instance name}. The value is an autogenerated random string. (If we are importing the same function app a second time from same APIM service, this step is not performed since the host key is already created).

Didieroc_5-1685031648960.png

 

Didieroc_6-1685031648964.png

 

6- Then it sends a PUT request to Microsoft.ApiManagement provider to create a named-value pair with the name {your Azure Function App instance name}-key. The value is a copy of the host key created in the previous step. (If we are importing the same function app into APIM a second time to create another API with different name, the same name value is used, no need to create a new named value).

Didieroc_7-1685031648967.png

 

7- Then it sends a POST/batch request to Microsoft.ApiManagement provider to create a backend object in APIM with the same name of the API being created. This backend is set with the following properties: For credentials it uses a header named x-functions-key (this header name MUST NOT BE CHANGED) and the value of this header is {{functionAppName-key}} which is a reference of the he named value created before, which contains the host key. The process also set up a Runtime URL for this backend object; the URL looks like https://<functionname>.azurewebsites.net/api which is the default domain of the function app being imported in APIM.  (If we are importing the same function app to APIM a second time to create another API with different name, the same backend object is used, no need to create a new one).

Didieroc_8-1685031648972.png

 

8- Then it sends a POST/batch request to Microsoft.ApiManagement provider to create the API operations based on the HTTP triggers it got from the function app in step #3.

Note: it creates 2 operations for each function, a POST and a GET operation.

Didieroc_9-1685031648978.png

 

9- Then it sends a POST/batch request to Microsoft.ApiManagement provider to create a policy for those API operations created in previous step, the policy looks like this: <set-backend-service id=”apim-generated-policy” backend-id=”functionAppName” /> this policy references the backend object created in step #7, to make use of the backend URL and host key when sending a request to the backend function app. This policy is set at the individual operation scope for each operation created.

Didieroc_10-1685031648986.png

 

Finally, the API is created successfully with all its setting mentioned above.

As noted above, the first of the import process is to create an empty API, so if any of the subsequent steps fail, the import process will send a DELETE request to Microsoft.ApiManagement provider to undo the API created in APIM, as it was unsuccessfully configured.

There are many reasons that may cause the import process to fail, let’s review the most common ones from the below Troubleshooting scenarios:

 

Note: The function app can be imported in APIM no matter if the function app is integrated with virtual network or private endpoint.

 

Symptom

Cause

Resolution

Unable to list function app keys.

Sometimes customers deploy their Function app from Terraform, DevOps, atc. And they do not generate app keys, so it fails to import function app in APIM if not keys are there.
It aslo may be an issue trying to retrieve keys from function app storage. Function runtime unreachable. Commonly you will see a 400 Bad request.

Ask customers to redeploy function apps but generating function keys. Or check if customer can list those keys from Azure portal or REST API to confirm keys are populated.

Unable to create a new host key in the function app.

A Ready-only lock in the function app avoids adding host keys.
Commonly you will see a 409 Conflict error even when trying to list keys.

Ask customer to remove lock and try the deployment again.


Consideration

Please be aware that the 9 steps described above are just the main actions of our interest and note that I am importing the API without specifying Tags, Products nor Versioning, so if you import the function app and select those additional options of course you will notice more requests and actions in the trace. 

 

Didieroc_0-1685116752172.png

 

 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Azure Storage - TLS 1.0 and 1.1 retirement

Overview TLS 1.0 and 1.1 retirement on Azure Storage was previously announced for Nov 1st, 2024, and it was postponed recently to 1 year later...

1 year ago

Efficient Management of Append and Page Blobs Using Azure Storage Actions

  Overview In Azure Storage, Blob Lifecycle Management (BLM) allows you to automate the management of your data based on rules defined by...

1 year ago

[Azure AI Search] Internal Server Error when creating CMK encrypted objects

Scenario Customers follow the Microsoft doc to create CMK encrypted objects (data source, index etc.), but get the 500 Internal Serv...

1 year ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Restoring Soft-Deleted Blobs with multithreading in Azure Storage Using C#

Blob soft delete is an essential feature that safeguards your data against accidental deletions or overwrites. By retaining deleted data for a...

1 year ago

Performing simple Azure Table Storage REST API operations using curl command.

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entit...

1 year ago

Bulk delete all the old jobs from the batch account

Deleting a Job also deletes all Tasks that are part of that Job, and all Job statistics. This also overrides the retention period for Task dat...

1 year ago

Utilizing Azure Storage and Runbooks for scheduled automated backups of Azure SQL Databases

In this article, we are going to provide detailed steps to create a scheduled Azure SQL Database backup to storage account using automation. T...

2 years ago

[Azure Service Bus] JMS messages getting dead-lettered

The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer connects to th...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.