1. Answers
  2. Consolidate Multiple Backends with Azure API Management

How do I consolidate multiple backend services with a single Azure API Management frontend?

Introduction

In this example, we will learn how to consolidate multiple backend services using a single Azure API Management (APIM) frontend. This allows you to provide a unified API surface for different services, improving maintainability and scalability. We’ll define an APIM instance, configure multiple APIs, and connect them to their respective backend services.

Detailed Explanation

  • Azure API Management: This service allows you to create consistent and modern API gateways for existing back-end services. Here, we’ll set up an APIM instance.
  • Backend Services: We’ll define multiple backend services that the APIM instance will route to based on the API path.
  • APIs: Define APIs within the APIM instance that map to backend services.

The resulting infrastructure will consist of:

  1. An API Management instance.
  2. Multiple APIs connected to different backend services.

This setup helps in ensuring that all API endpoints are managed and exposed through a single gateway, providing easier maintenance, monitoring, and security.

import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

const example = new azure.core.ResourceGroup("example", {
    name: "example-resources",
    location: "East US",
});
const exampleService = new azure.apimanagement.Service("example", {
    name: "example-apim",
    location: example.location,
    resourceGroupName: example.name,
    publisherName: "example@example.com",
    publisherEmail: "example@example.com",
    skuName: "Developer_1",
});
const exampleApi1 = new azure.apimanagement.Api("example_api1", {
    name: "example-api1",
    resourceGroupName: example.name,
    apiManagementName: exampleService.name,
    revision: "1",
    displayName: "Example API 1",
    path: "service1",
    protocols: ["https"],
    "import": {
        contentFormat: "swagger-link-json",
        contentValue: "https://example.com/swagger/service1.json",
    },
});
const exampleApi2 = new azure.apimanagement.Api("example_api2", {
    name: "example-api2",
    resourceGroupName: example.name,
    apiManagementName: exampleService.name,
    revision: "1",
    displayName: "Example API 2",
    path: "service2",
    protocols: ["https"],
    "import": {
        contentFormat: "swagger-link-json",
        contentValue: "https://example.com/swagger/service2.json",
    },
});
export const apiManagementUrl = exampleService.gatewayUrl;
export const api1Url = pulumi.interpolate`${exampleService.gatewayUrl}/${exampleApi1.path}`;
export const api2Url = pulumi.interpolate`${exampleService.gatewayUrl}/${exampleApi2.path}`;

Key Points

  • Set up an Azure API Management instance as a centralized API gateway.
  • Defined two APIs within the APIM instance each mapping to different backend services.
  • Connected both APIs using the OpenAPI (Swagger) specification hosted on external URLs.

Summary

We have created an Azure API Management instance and configured it to route requests to multiple backend services. This consolidation approach provides a streamlined and manageable way to expose APIs from varied services through a single point of access.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up