Automate Import of Functions/WebAPI in Azure API Management as backend and using OpenAPI definition and Terraform

 When hosting APIs in Azure it is more and more common to make them available for consumption via an API Management Gateway. The advantages of using a API Management gateway are well known. 

When adding a Function/WebAPI to an API Management gateway, the most common method is to add the Function/WebAPI as a backend in API Management and then exposing the Function/WebAPI as an API that uses this backend to process requests.

There is a very simple way to do this using the Azure Portal. The portal allows connecting an existing Function or WebAPI inside the API Management gateway. 


The portal now also allows to expose a function/web api from the action pane of functions and web api.


While this makes it very easy to add APIs to API Management gateway using the portal, this would very soon become unmanageable and for more complex and automated environments, the obvious tilt would then be towards a automated deployment using one of the Infrastructure as Code (IaC) possibilities.

In this example, I have used Terraform to create my IaC deployment. The same process can also be applied using ARM.

Steps to add a function app as an API in API Management are as follows:

1. Create a OpenAPI specification for your function app.

2. Add function as a backend to API Management3. Import API and Operations of the function using OpenAPI specifications4. Add a API policy to set the backend to the already created backend

That is it. Now you can replicate this for any number of Functions and WebAPIs. Tie this into your deployment pipeline and you have a completely automated way to expose your APIs via your API Management gateway.

Comments

  1. Do you have suggestions on how to automate the generation of the openapi specification of your function app?

    ReplyDelete
  2. Beyond FunctionV1 there is no inherent support for spec generation from code. On the other hand, Design First spec definition is now considered the standard for API development due to the overall flexibilities that it allows. Comparing Code First vs Design First, I would prefer design first over code first.

    ReplyDelete

Post a Comment

Popular posts from this blog

Microsoft Graph PowerShell SDK without Admin Rights

Managing built-in cache in Azure API Management