Companies implement Azure APIM to control access to their APIs. By implementing subscriptions and products, administrators can ensure every request is authenticated and validated, while protecting their backend system. When those are on-premise, there a number of reasons why a company would want to keep all the traffic within their network. They are:
Enter Azure APIM Self-Hosted Gateways. This feature allows you to provide secure, on-prem API access with cloud-based Azure APIM Management. They are fantastic way to improve internal traffic communication and performance, with all the benefits of a centralized, cloud-hosted management experience. Double win!
For this article, I created the following architecture to demonstrate how/when you may want to use a self-hosted gateway for your Azure APIM service.
The architecture consists of the following main components:
Azure APIM
An Azure APIM service to manage the APIs.
On-Prem API
An API running on-prem (local) on the corporate network that returns the current time when a request is made to it.
Azure APIM Self-Hosted Gateway
This is the on-prem container image deployed within the network.
Azure APIM API Registration
The registration for the API within the Azure APIM service. Note that the URL for the API is configured to be an internal IP.
On-Prem user
Our internal developer that just wants to do his job and doesn’t care about where/how the API is managed.
Communication Flow
The desired communication would be:
Now, let me show you how to implement a self-hosted gateway…
The first step is to create my self-hosted gateway within the Azure APIM service.
The following link provides a tutorial for creating the self-hosted gateway:
Provision a self-hosted gateway in Azure API Management | Microsoft Docs
In the APIM service, I select the Gateways option.
I assign a name and location for the gateway and select the API(s) to associate.
An API can be associated with multiple gateways (Azure, self-hosted, etc.). The required traffic patterns and routing will determine the best setup for the environment. It’s entirely possible to have an API associated with both a self-hosted gateway and an Azure APIM gateway.
Once the gateway is created, I select the Deployment tab to see the connection details. Azure APIM provides Docker and Kubernetes commands to help you use the new container image in your environment.
Azure APIM self-hosted gateways leverage a pre-configured container image. Included with this is an env.conf file that contains the specifics for your Azure APIM service and subscription.
I download env.conf file and review the supplied Docker command. Because I am running the image in Docker Desktop on my machine, I update my port mappings to work in my local environment.
docker run -d -p 1111:8080 -p 2222:8081 --name BSoltisDemoGateway --env-file env.conf mcr.microsoft.com/azure-api-management/gateway:latest
With the command successfully executed, I confirm the Docker container was created and running, using Docker Desktop.
I open the Logs for the new image. The logs will be used in testing the environment.
With the gateway created and running, I am ready to test the solution. Because I am simulating “local” traffic, I execute a request to local IP for the self-hosted gateway and confirm the response.
In the Docker Desktop Logs, I confirm the request is logged within the gateway container.
Lastly, I confirm the request is logged with in the Azure APIM service.
Because the self-hosted gateway maintains a connection to Azure APIM, all requests/traffic can be logged to Azure, while all traffic to the API is kept internal.
While Azure APIM Self-Hosted Gateways are extremely powerful components, there are few important aspects developers should note:
OK, hopefully that was pretty awesome information to learn. I’m continually impressed with how much can be accomplished with Azure APIM and the multitude of ways they can be leveraged. Now that you know what Azure APIM self-hosted gateways are and how you may use them, you may wonder what comes next?
Azure APIM continues to be one of my favorite parts of the Azure platform. With so many customization and integrations options, organizations can leverage these powerful Azure services for a variety of architectures and applications. Self-hosted gateways help improve performance, while ensuring secure and efficient API traffic. Be sure to check out the links below to read up on the latest Azure APIM features and how self-hosted gateways can empower your developers. Good luck!