question

NP-3046 avatar image
0 Votes"
NP-3046 asked 62261484 commented

Link existing function app with APIM using Azure CLI

Hello,

Azure Function App can be registered under (or linked with) API management in two ways:

  1. Function App -> API Management -> Link API

  2. API Management -> Add API -> Import function app.

Either options can be chosen over the portal. However, the key objective is to do the same (#1 or #2) with automation, i.e using Azure CLI.

With some discovery, looks like "az apim api import ... " would import the API with open API or swagger specification files, which doesn't meet the mentioned objective. Please provide if there are any references/samples available on executing on this requirement.

If there is no such option with Azure CLI, then the function API need to be registered as basic API (blank API) and create necessary operation. Perhaps, this would introduce more work.




azure-functionsazure-api-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PramodValavala-MSFT avatar image
0 Votes"
PramodValavala-MSFT answered 62261484 commented

Both options leverage ARM REST APIs to perform discovery and automate the process of importing a function app (or logic app even) into APIM. You can see the various requests made in the developer console of your browser.

Unfortunately, the same isn't available in the CLI or PowerShell cmdlets. Please feel free to raise a feature request to include support for the same.

The recommended way as highlighted in the Azure APIM DevOps Resource Kit is to author and maintain OpenAPI Specs + ARM Templates to automate the deployment of APIM and its sub-resources (like APIs, Products, etc.), which you could build upon for your own requirements.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hey! I don't know if you still need some help, but I just created a python script that uses the Azure Powershell commands and makes it (I hope for you as well) easier to automate azure function api imports to APIM.

You basically provide all you operations, apim name, ressource groups, etc. into a json input file that is interpreted by the script.

https://github.com/vitonimal/azfun-apim-importer

NOTE: I still need to do some better error handling to grab the stderr from the subprocess, but it is working fine on my end.

Peace!

Vitonimal

1 Vote 1 ·

Thanks for your response Pramod.

Is there any possibility of enabling App insights for an API in APIM through Azure CLI ?. I browsed for such options, however didn't find the relevant docs for that too.

0 Votes 0 ·

Looks like the Azure CLI doesn't support setting the diagnostic settings for APIs but you could leverage the PowerShell cmdlet or directly the REST API. The REST API can be invoked using Azure CLI via the az rest command.

As for adding support with a dedicated command, feel free to raise an issue on the Azure CLI Repo.


0 Votes 0 ·