Skip to content

Commit cc177b0

Browse files
Add Apim-Samples files
1 parent cbbeb24 commit cc177b0

File tree

63 files changed

+4547
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4547
-2
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
[*.md]
14+
trim_trailing_whitespace = false
15+
16+
[*.bicep]
17+
indent_size = 2
18+
19+
[*.yaml]
20+
indent_size = 2
21+
22+
[*.yml]
23+
indent_size = 2

.github/workflows/python-tests.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Python Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: [ '3.12', '3.13' ]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -r requirements.txt
25+
- name: Run tests
26+
run: |
27+
python -m unittest discover shared/python-tests

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*.egg-info/
5+
.venv/
6+
venv/
7+
env/
8+
9+
# Jupyter
10+
.ipynb_checkpoints/
11+
12+
# VS Code
13+
.vscode/
14+
15+
# Azure
16+
.azure/
17+
18+
# Bicep/ARM/Infra
19+
params*.json
20+
policy-updated.xml
21+
labs-in-progress/
22+
23+
# Misc
24+
*.log
25+
26+
# Exclude sensitive or generated files
27+
.env

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Contributing to Azure API Management Samples
2+
3+
Thank you for your interest in contributing!
4+
5+
## How to Contribute
6+
7+
- Fork the repository and create your branch from `main`.
8+
- Make your changes, following the existing code style and structure.
9+
- Add or update documentation and tests as needed.
10+
- Ensure your code passes linting and runs as expected.
11+
- Open a pull request with a clear description of your changes.
12+
13+
## Guidelines
14+
15+
- Use standard Python and Bicep best practices.
16+
- Keep reusable assets in the `shared` folder.
17+
- For infrastructure or sample changes, update the relevant `create.ipynb` and `main.bicep` files.
18+
- Keep documentation clear and concise.
19+
20+
## Code of Conduct
21+
22+
Please be respectful and considerate in all interactions.
23+
24+
---
25+
26+
For questions or suggestions, please open an issue or reach out to the author.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Simon Kurtz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,108 @@
1-
# Apim-Samples
2-
This repository provides a playground to safely experiment with and learn Azure API Management (APIM) policies in various architectures.
1+
# Azure API Management Samples
2+
3+
This repository provides a playground to safely experiment with and learn Azure API Management (APIM) policies in various architectures.
4+
5+
## Objectives
6+
7+
1. Educate you on common APIM architectures we see across industries and customers.
8+
1. Empower you to safely experiment with APIM policies.
9+
1. Provide you with high-fidelity building blocks to further your APIM integration efforts.
10+
11+
_Try it out, learn from it, apply it in your setups._
12+
13+
## Repo Structure
14+
15+
### High-level
16+
17+
- All _samples_ can be found in the `samples` folder. Samples showcase functionality and provide a baseline for your experimentation.
18+
- All _infrastructures_ can be found in the `infrastructure` folder. They provide the architectural underpinnings.
19+
- All shared code, modules, functionality, policies, etc. can be found in the `shared` folder.
20+
- Bicep _modules_ are versioned in the `bicep/modules` folder. Major changes require versioning.
21+
- Python _modules_ are found in the `python` folder. _They are not versioned yet but may be in the future._
22+
- Reusable _APIM policies_ are found in the `apim-policies` folder.
23+
- Reusable Jupyter notebooks are found in the `jupyter` folder.
24+
25+
### Sample Setup
26+
27+
- Each sample uses an architecture infrastructure. This keeps the samples free of almost all setup.
28+
- Each infrastructure and sample features a `create.ipynb` for creation (and running) of the sample setup and a `main.bicep` file for IaC configuration.
29+
- Each infrastructure contains a `clean-up.ipynb` file to tear down everything in the infrastructure and its resource group. This reduces your Azure cost.
30+
- Samples (and infrastructures) may contain additional files specific to their use cases.
31+
32+
### Infrastructure Architectures
33+
34+
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](https://learn.microsoft.com/azure/cloud-adoption-framework/scenarios/app-platform/api-management/landing-zone-accelerator) for up-to-date production setups.
35+
36+
- [Simple API Management](./infrastructure/simple-apim)
37+
- Just the basics with a publicly accessible API Management intance fronting your APIs. This is the innermost way to experience and experiment with the APIM policies.
38+
- [API Management & Container Apps](./infrastructure/apim-aca)
39+
- APIs are often times implemented in containers that are running in Azure Container Apps. This architecture accesses the container apps publicly. It's beneficial to test both APIM and container app URLs here to contrast and compare experiences of API calls through and bypassing APIM. It is not intended to be a security baseline.
40+
- [Secure Front Door & API Management & Container Apps](./infrastructure/afd-apim)
41+
- A higher-fidelity implementation of a secured setup in which Azure Front Door connects to APIM via the new private link integration. This traffic, once it traverses through Front Door, rides entirely on Microsoft-owned and operated networks. Similarly, 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). It's noteworthy that we are using APIM Standard V2 here as we need the ability to accept a private link from Front Door.
42+
43+
---
44+
45+
## Getting Started
46+
47+
### Prerequisites
48+
49+
These prerequisites apply broadly across all infrastructure and samples. If there are specific deviations, expect them to be noted there.
50+
51+
- [Python 3.12](https://www.python.org/) installed
52+
- Python 3.13 may not have all dependencies ready yet. There have been issues during installs.
53+
- [VS Code](https://code.visualstudio.com/) installed with the [Jupyter notebook extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) enabled
54+
- [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) installed
55+
- [An Azure Subscription](https://azure.microsoft.com/free/) with Owner or Contributor+UserAccessAdministrator permissions. Execute [shared/jupyter/verify-az-account.ipynb](shared/jupyter/verify-az-account.ipynb) to verify.
56+
- [Sign in to Azure with Azure CLI](https://learn.microsoft.com/cli/azure/authenticate-azure-cli-interactively)
57+
58+
### Initialization
59+
60+
Run through the following steps to create a Python virtual environment before doing anything else:
61+
62+
1. Open VS Code.
63+
1. Invoke the _Command Palette_ via the _View_ menu or a shortcut (on Windows: Ctrl + Shift + P).
64+
1. Select _Python: Create Environment_.
65+
1. Select _Venv_ as we want a local virtual environment.
66+
1. Select the desired, installed Python version.
67+
1. Check _requirements.txt_ to install the Python dependencies we need for this repo, then press _OK_. The install may take a few minutes. You can check on progress in the _OUTPUT_ window.
68+
1. Verify the virtual environment is set up. You should see a new _.venv_ directory with a _pyveng.cfg_ file and the Python version you selected earlier.
69+
70+
The first time you run a Jupyter notebook, you'll be asked to install the Jupyter kernel package (ipykernel).
71+
72+
### Running a Sample
73+
74+
1. Locate the specific sample's `create.ipynb` file and adjust the parameters under the `User-defined Parameters` header as you see fit.
75+
1. Ensure that the specified infrastructure already exists in your subscription. If not, proceed to the desired infrastructure folder and execute its `create.ipynb` file. Wait until this completes before continuing.
76+
1. Execute the sample's `create.ipynb` file.
77+
78+
Now that infrastructure and sample have been stood up, you can experiment with the policies, make requests against APIM, etc.
79+
80+
---
81+
82+
## Development
83+
84+
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.
85+
86+
The repo uses the bicep linter and has rules defined in `bicepconfig.json`. See the [bicep linter documentation](https://learn.microsoft.com/azure/azure-resource-manager/bicep/bicep-config-linter) for details.
87+
88+
We welcome contributions! Please consider forking the repo and creating issues and pull requests to share your samples. Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. Thank you!
89+
90+
### Testing
91+
92+
Python modules and files in the `shared` folder are supported with tests in the `python-tests` folder. They can be invoked manually via `pytest -v` but are also run upon push to GitHub origin. The `pytest.ini` file in the root sets up the test structure.
93+
94+
Additional information can be found [here](# https://docs.pytest.org/en/8.2.x/).
95+
96+
---
97+
98+
## Supporting Resources
99+
100+
The APIM team maintains an [APIM policy snippets repo](https://github.com/Azure/api-management-policy-snippets) with use cases we have seen. They are not immediately executable samples and require integrations such as in this repo.
101+
102+
---
103+
104+
## Acknowledgements
105+
106+
This project has its roots in work done by [Alex Vieira](https://github.com/vieiraae) on the excellent Azure API Management [AI Gateway](https://github.com/Azure-Samples/AI-Gateway) GitHub repository. Much of the structure is similar and its reuse resulted in significant time savings. Thank you, Alex!
107+
108+
Furthermore, [Houssem Dellai](https://github.com/HoussemDellai) was instrumental in setting up a working Front Door to API Management [private connectivity lab](https://github.com/Azure-Samples/AI-Gateway/tree/main/labs/private-connectivity). This created a working baseline for one of this repository's infrastructures. Thank you, Houssem!

bicepconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"analyzers": {
3+
"core": {
4+
"enabled": true,
5+
"rules": {
6+
"no-unused-params": {
7+
"level": "off"
8+
},
9+
"no-unused-vars": {
10+
"level": "off"
11+
},
12+
"outputs-should-not-contain-secrets": {
13+
"level": "off"
14+
}
15+
}
16+
}
17+
}
18+
}

diagrams/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# PlantUML Diagrams
2+
3+
This directory contains PlantUML diagrams for the Azure API Management architecture.
4+
Azure Symbols are on [GitHub](https://github.com/plantuml-stdlib/Azure-PlantUML/blob/master/AzureSymbols.md)
5+
6+
## Using PlantUML in VS Code
7+
8+
1. **Prerequisites**:
9+
- Java is installed (e.g. OpenJDK 22)
10+
- PlantUML VS Code extension is installed
11+
- Graphviz (optional, for more complex diagrams)
12+
- Configure PlantUML settings in `.vscode\settings.json`. Ensure that you set the `plantuml.java` path appropriately for your Java executable:
13+
14+
```json
15+
"plantuml.render": "Local",
16+
"plantuml.exportFormat": "svg",
17+
"plantuml.java": "C:\\Program Files\\OpenJDK\\jdk-22.0.2\\bin\\java.exe",
18+
"plantuml.diagramsRoot": "diagrams/src",
19+
"plantuml.exportOutDir": "diagrams/out"
20+
```
21+
22+
2. **Viewing Diagrams**:
23+
- Open any `.puml` file in this directory
24+
- Right-click in the editor and select "PlantUML: Preview Current Diagram"
25+
- Alternatively, use the Alt+D keyboard shortcut
26+
27+
3. **Exporting Diagrams**:
28+
- Right-click in the editor and select "PlantUML: Export Current Diagram"
29+
- Select your desired output format (PNG, SVG, PDF, etc.)
30+
31+
## Troubleshooting
32+
33+
If you encounter issues with PlantUML:
34+
35+
1. **Java Path Issues**:
36+
- Ensure Java is on your system PATH
37+
- If VS Code terminal can't find Java, try restarting VS Code
38+
- You may need to configure the specific Java path in VS Code settings
39+
40+
2. **PlantUML Extension Configuration**:
41+
- Open VS Code settings (Ctrl+,)
42+
- Search for "plantuml"
43+
- Set "plantuml.java" to the path of your Java executable if needed
44+
- You can also set "plantuml.jarPath" to a specific PlantUML jar file
45+
46+
3. **Alternative Rendering**:
47+
- If local rendering fails, try using the PlantUML server:
48+
- Change "plantuml.render" setting to "PlantUMLServer"

diagrams/out/afd-apim-aca-architecture/Azure Front Door, API Management & Container Apps Architecture.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)