This repository provides resources to quickly deploy high-fidelity Azure API Management (APIM) infrastructures and experiment with common APIM.
Historically, there were two general paths to experimenting with APIM. Standing up an entire landing zone with the APIM Landing Zone Accelerator can feel overwhelming and more than needed. Similarly, using APIM policy snippets is only helpful when an APIM instance and infrastructure already exists.
β APIM Samples provides common APIM infrastructures and real-world samples. Most samples can be deployed to any infrastructure, yielding an innovative and highly powerful and flexible Γ la carte approach!
π‘ APIM Samples is _neither too much nor too little. It is just right!
- Educate on common APIM architectures we see across industries and customers.
- Empower to safely experiment with APIM policies.
- Provide high-fidelity building blocks to further your APIM integration efforts.
It's quick and easy to get started!
- Follow one of the two setup options.
- Select an infrastructure to deploy.
Details
| Infrastructure Name | Description |
|---|---|
| Simple API Management | Just the basics with a publicly accessible API Management instance fronting your APIs. This is the innermost way to experience and experiment with the APIM policies. |
| API Management & Container Apps | APIs are often implemented in containers running in Azure Container Apps. This architecture accesses the container apps publicly. It's beneficial to test both APIM and container app URLs to contrast and compare experiences of API calls through and bypassing APIM. It is not intended to be a security baseline. |
| Front Door & API Management & Container Apps | A secure implementation of Azure Front Door connecting to APIM via the new private link integration! This traffic, once it traverses through Front Door, rides entirely on Microsoft-owned and operated networks. The connection from APIM to Container Apps is secured but through a VNet configuration (it is also entirely possible to do this via private link). APIM Standard V2 is used here to accept a private link from Front Door. |
| Application Gateway (Private Endpoint) & API Management & Container Apps | A secure implementation of Azure Application Gateway connecting to APIM via the new private link integration! This traffic, once it traverses through App Gateway, uses a private endpoint set up in the VNet's private endpoint subnet. The connection from APIM to Container Apps is secured but through a VNet configuration (it is also entirely possible to do this via private link). APIM Standard V2 is used here to accept a private link from App Gateway. |
| Application Gateway (VNet) & API Management & Container Apps | Full VNet injection of APIM and ACA! APIM is shielded from any type of traffic unless it comes through App Gateway. This offers maximum isolation for instances in which customers seek VNet injection. |
Details
| Sample Name | Description | Supported Infrastructure(s) |
|---|---|---|
| AuthX | Authentication and role-based authorization in a mock HR API. | All infrastructures |
| AuthX Pro | Authentication and role-based authorization in a mock product with multiple APIs and policy fragments. | All infrastructures |
| General | Basic demo of APIM sample setup and policy usage. | All infrastructures |
| Load Balancing | Priority and weighted load balancing across backends. | apim-aca, afd-apim (with ACA) |
| Secure Blob Access | Secure blob access via the valet key pattern. | All infrastructures |
| Credential Manager (with Spotify) | Authenticate with APIM which then uses its Credential Manager with Spotify's REST API. | All infrastructures |
| Azure Maps | Proxying calls to Azure Maps with APIM policies. | All infrastructures |
Use the interactive Developer CLI to verify setup, run tests, and manage your development workflow:
Windows:
.\start.ps1macOS / Linux:
./start.shThis menu-driven interface provides quick access to:
- Setup: Complete environment setup, verify local setup, and show Azure account info
- Tests: Run pylint, pytest, and full Python checks
APIM Samples supports two setup options:
Details
The fastest way to get started is using our pre-configured development environment.
Each supported Python version has its own dev container, providing you with a more tailored environment that hopefully more closely resembles your own workloads.
GitHub Codespaces: Click the green "Code" button β "Codespaces" β "..." β "New with options..." β "Dev container configuration" (select Python version but ignore Default project configuration) β "Create codespace"
VS Code Dev Containers: Alternatively, you can run the dev container locally by installing the Dev Containers extension, then selecting "Reopen in Container".
- Open the repository in the dev container environment
- Wait for the automatic setup to complete (includes interactive Azure CLI configuration)
- If prompted during setup, choose your preferred Azure CLI authentication method:
- Mount local config: Preserves authentication between container rebuilds
- Manual login: Requires tenant-specific
az loginafter each container startup - Configure later: Skip for now, configure manually later
- Sign in to Azure with correct tenant and subscription:
- If you chose manual login or skipped:
az login --tenant <your-tenant-id-or-domain> - Set the correct subscription:
az account set --subscription <your-subscription-id-or-name> - Verify your authentication context:
az account show
- If you chose manual login or skipped:
- Verify your Azure setup by executing shared/jupyter/verify-az-account.ipynb
All prerequisites are automatically installed and configured.
π For detailed setup information, troubleshooting, and optimization details, see Dev Container Documentation
Details
These prerequisites apply broadly across all infrastructure and samples. If there are specific deviations, expect them to be noted there.
- Python 3.12, 3.13, and 3.14 are all supported
- VS Code installed with the Jupyter notebook extension enabled
- Azure CLI installed
- Azure Bicep installed
- An Azure Subscription with Owner or Contributor+UserAccessAdministrator permissions. Execute Verify Azure Account to verify.
- Azure Authentication: Sign in to Azure with Azure CLI using the specific tenant and subscription you want to work with:
- To log in to a specific tenant:
az login --tenant <your-tenant-id-or-domain> - To set a specific subscription:
az account set --subscription <your-subscription-id-or-name> - To verify your current context:
az account show - See the Azure CLI authentication guide for more options
- To log in to a specific tenant:
- Create Python Environment: In VS Code, use Ctrl+Shift+P β "Python: Create Environment" β "Venv" β Select Python version β Check requirements.txt
The install may take a few minutes. You can check on progress in the OUTPUT window (selectPython). - Complete Environment Setup: Open a terminal and start the Developer CLI, then select
Complete environment setup. - Restart VS Code to apply all settings
- Sign in to Azure:
az login --tenant <your-tenant-id>andaz account set --subscription <your-subscription> - Verify local setup: Start the Developer CLI, then select
Verify local setup.
The first time you run a Jupyter notebook, you may be asked to install the Jupyter kernel package (ipykernel) if not already available.
When you open any .ipynb notebook, it will automatically use the correct kernel and all imports will work seamlessly.
- Open the desired sample's
create.ipynbfile. - Optional: Adjust the parameters under the
User-defined Parametersheader, if desired. - Execute the
create.ipynbJupyter notebook viaRun All.
A supported infrastructure does not yet need to exist before the sample is executed. The notebook will determine the current state and present you with options to create or select a supported infrastructure, if necessary.
Now that infrastructure and sample have been stood up, you can experiment with the policies, make requests against APIM, etc.
The Python helpers in this repo use standard-library logging, empowering you to control verbosity via environment variables in the root .env file. This file is created via the APIM Samples Developer CLI.
APIM_SAMPLES_LOG_LEVEL: Controls the overall verbosity (DEBUG,INFO,WARNING,ERROR,CRITICAL). Default:INFO.- When set to
DEBUG, the Azure CLI runner in shared/python/azure_resources.py will also add--debugto simpleaz ...commands.
- When set to
APIM_SAMPLES_CONSOLE_WIDTH: Optional wrap width for long lines (defaults to120).
Encountering issues? Check our comprehensive Troubleshooting Guide! which covers:
- Deployment Errors - Including the common "content already consumed" error and parameter mismatches
- Authentication Issues - Azure CLI login problems and permission errors
- Notebook & Development Environment Issues - Module import errors and Python path problems
- Azure CLI Issues - Rate limiting and API version compatibility
- Resource Management Issues - Resource group and APIM service problems
For immediate help with common errors, diagnostic commands, and step-by-step solutions, see TROUBLESHOOTING.md.
- All samples can be found in the
samplesfolder. Samples showcase functionality and provide a baseline for your experimentation. - All infrastructures can be found in the
infrastructurefolder. They provide the architectural underpinnings. - All shared code, modules, functionality, policies, etc. can be found in the
sharedfolder.- Bicep modules are versioned in the
bicep/modulesfolder. Major changes require versioning. - Python modules are found in the
pythonfolder. They are not versioned yet but may be in the future. - Reusable APIM policies are found in the
apim-policiesfolder. - Reusable Jupyter notebooks are found in the
jupyterfolder.
- Bicep modules are versioned in the
- Each sample uses an architecture infrastructure. This keeps the samples free of almost all setup.
- Each infrastructure and sample features a
create.ipynbfor creation (and running) of the sample setup and amain.bicepfile for IaC configuration. - Each infrastructure contains a
clean-up.ipynbfile to tear down everything in the infrastructure and its resource group. This reduces your Azure cost. - Samples (and infrastructures) may contain additional files specific to their use cases.
We provide several common architectural approaches to integrating APIM into your Azure ecosystem. While these are high-fidelity setups, they are not production-ready. Please refer to the Azure API Management landing zone accelerator for up-to-date production setups.
As you work with this repo, you will likely want to make your own customizations. There's little you need to know to be successful.
The repo uses the bicep linter and has rules defined in bicepconfig.json. See the bicep linter documentation for details.
We welcome contributions! Please consider forking the repo and creating issues and pull requests to share your samples. Please see CONTRIBUTING.md for details. Thank you!
The repository uses pylint to maintain Python code quality standards. The configuration is located in tests/python/.pylintrc, and the Developer CLI supports linting.
Python modules in shared/python are covered by comprehensive unit tests located in tests/python. All tests use pytest and leverage modern pytest features, including custom markers for unit and HTTP tests. The Developer CLI supports testing.
Adding a new sample is relatively straight-forward.
- Create a new feature branch for the new sample.
- Copy the
/samples/_TEMPLATEfolder. - Rename the copied folder to a name representative of the sample (e.g. "load-balancing", "authX", etc.)
- Change the
create.ipynbandmain.bicepfiles. Look for the brackets ([ ]) brackets for specific inputs. - Add any policy.xml files to the same folder if they are specific to this sample. If they are to be reused, place them into the
/shared/apim-policiesfolder instead. - Test the sample with all supported infrastructures.
- Create a pull request for merge.
This project has its roots in work done by Alex Vieira on the excellent Azure API Management AI Gateway GitHub repository. Much of the structure is similar and its reuse resulted in significant time savings. Thank you, Alex!
Furthermore, Houssem Dellai was instrumental in setting up a working Front Door to API Management private connectivity lab. This created a working baseline for one of this repository's infrastructures. Thank you, Houssem!
Andrew Redman for contributing the Azure Maps sample.
The original author of this project is Simon Kurtz.
- AI Gateway
- Landing Zone Accelerator
- Learning Modules
- News and announcements
- APIM Releases
- APIM policy snippets repo
For much more API Management content, please also check out APIM Love.
Important
This software is provided for demonstration purposes only. It is not intended to be relied upon for any purpose. The creators of this software make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the software or the information, products, services, or related graphics contained in the software for any purpose. Any reliance you place on such information is therefore strictly at your own risk.