| AWS (aws_infra/) | Azure (this guide) | Free? |
|---|---|---|
| S3 (index.html, scripts.js) | Static Web Apps, Free plan | Yes |
| API Gateway | API Management, Consumption tier | First 1M calls/month free |
| Lambda (2 functions) | Azure Functions, Flex Consumption (Python) | First 250k executions + 100k GB-s/month free |
| DynamoDB | Cosmos DB (NoSQL API), Free tier | First 1000 RU/s + 25 GB free (1 account per subscription) |
Request flow: Browser → Static Web App (page) → APIM (/employees) → Function → Cosmos DB
Code in this repo:
getEmployee.py and insertEmployeeData.py).What changed from the AWS code, and why:
boto3 is replaced by the azure-cosmos library.id. We set id = empId. Saving the same empId twice overwrites the item, same as DynamoDB put_item./empId, like DynamoDB's partition key.scripts.js now sends GET and POST to /employees, and table cells are filled with .text() instead of string concatenation (prevents script injection).scripts.js; the order is fixed.az (Azure CLI) and func (Functions Core Tools) are installed on your Mac. Run az login once.brew install python@3.11.eastus) so latency and data-transfer costs stay low. Below, replace names in <angle brackets>. Storage, Function and APIM names must be globally unique.The steps use the Azure Portal (https://portal.azure.com) because you are learning. The
azcommand for each step is shown too; it is what Terraform will model later.
A resource group is a folder that holds everything for this project. Deleting it later removes everything, so cleanup is one click.
Portal: Resource groups → Create → name rg-employee-app, region East US → Review + create.
az group create --name rg-employee-app --location eastus
Portal: Create a resource → Azure Cosmos DB → Azure Cosmos DB for NoSQL → Create.
rg-employee-app<cosmos-name> (unique)Why provisioned and not serverless? The free tier only works with provisioned throughput. It gives 1000 RU/s free, and we will use 400.
If the Apply option is greyed out, another account in the subscription already uses the free tier. Choose Serverless instead; at this scale it costs cents.
Then create the database and container:
employeesdb. Leave "Provision database throughput" unchecked.employeeProfile/empId400 RU/s (the minimum, within the free grant). OK.Copy the connection string: account → Settings → Keys → Primary Connection String. Treat it like a password.
Portal: Create a resource → Function App → Flex Consumption → Create.
rg-employee-app; name <func-name>; region: sameFlex Consumption scales to zero when idle, so you pay nothing when nobody uses the app. Do not set "Always ready instances".
Add the secret as an app setting: Function App → Settings → Environment variables → App settings → Add:
COSMOS_CONNECTION_STRING, value = the string from Step 2 → Apply, then Confirm.Optional local test first:
cd azure_functions
python3.11 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp local.settings.json.sample local.settings.json # then paste the connection string into it
func start
# in another terminal:
curl -X POST localhost:7071/api/employees -H "Content-Type: application/json" \
-d '{"empId":"1","empFirstName":"Sharath","empLastName":"Holla","empAge":"26"}'
curl localhost:7071/api/employees
local.settings.json is in .gitignore; never commit it.
Deploy to Azure:
az login
cd azure_functions
func azure functionapp publish <func-name>
The output lists the function URLs. Test the live function:
curl https://<func-name>.azurewebsites.net/api/employees
(Flex Consumption may use a longer hostname like <func-name>-xxxx.<region>-01.azurewebsites.net. Copy it from the Function App Overview → URL.)
You should see the Sharath item (or [] if you skipped the local test). The first call after idle can take a few seconds (cold start).
In Data Explorer (Cosmos), open employeeProfile → Items to confirm the data is there.
Portal: Create a resource → API Management → Create.
rg-employee-app; region: same; name <apim-name>Add the API:
employee-api; Web service URL = https://<func-name>.azurewebsites.net/api (use the real function hostname from Step 4)Add the two operations (like the two API Gateway methods):
get employees, verb GET, URL /employees → Savesave employee, verb POST, URL /employees → SaveTurn off the subscription key requirement: API → Settings tab → untick Subscription required → Save. (Your API Gateway had no key either. The key would otherwise have to be placed in browser JavaScript, where anyone could read it.)
Add CORS. Browsers block calls from one domain (your Static Web App) to another (APIM) unless the API allows it. API → All operations → Inbound processing → </> (code editor) and replace the <inbound> section with:
<inbound>
<cors allow-credentials="false">
<allowed-origins>
<origin>https://<your-static-web-app-hostname></origin>
</allowed-origins>
<allowed-methods>
<method>GET</method>
<method>POST</method>
</allowed-methods>
<allowed-headers>
<header>Content-Type</header>
</allowed-headers>
</cors>
<base />
</inbound>
Find <your-static-web-app-hostname> in the Portal: Static Web App → Overview → URL (for example yellow-plant-07edff50f.azurestaticapps.net; no trailing slash). Note: the Consumption tier does not allow rate-limit-by-key or quota-by-key policies (APIM rejects them), so there is no per-IP limit. To cap cost, keep the Function App's maximum instance count low (Function App → Scale and concurrency) and set an Azure budget alert.
Test in APIM: Test tab → get employees → Send. You should get HTTP 200 with the JSON.
Your gateway URL is on the APIM Overview page: https://<apim-name>.azure-api.net. Your endpoint is https://<apim-name>.azure-api.net/employees.
API_ENDPOINT to https://<apim-name>.azure-api.net/employees.main:
git add index.html profile.html scripts.js azure_functions AZURE_SETUP.md
git commit -m "Add employee profile app on Azure"
git push
azure-static-web-apps-yellow-plant-07edff50f.yml, app_location: "/") uploads the repo root to the Static Web App. The azure_functions folder is ignored because api_location is empty, which is intended.https://<your-static-web-app-hostname>/profile.html. Save a profile, then click "View all the Employee Profiles".| Symptom | Likely cause |
|---|---|
| Browser console shows a CORS error | The origin in the APIM <cors> policy doesn't exactly match the page URL (check https://, no trailing slash) |
alert("error") on page, APIM test works |
Wrong API_ENDPOINT, or the CORS issue above (press F12 → Network tab) |
| APIM returns 500/404 | Web service URL wrong or missing /api; test the Function URL directly first |
| Function returns 500 | COSMOS_CONNECTION_STRING missing, or the database/container names differ from employeesdb / employeeProfile |
| Pipeline doesn't pick up the change | Check the build in Azure DevOps Pipelines |
Everything is serverless or free-tier. Expect about a few cents per month, mostly from the Function's storage account. To remove everything:
az group delete --name rg-employee-app
(The Static Web App is in its own resource group; delete that too if you want it gone.)
After this works, each portal step maps to a Terraform resource: azurerm_resource_group, azurerm_cosmosdb_account (free_tier_enabled = true) with azurerm_cosmosdb_sql_database and azurerm_cosmosdb_sql_container, azurerm_storage_account, azurerm_function_app_flex_consumption, azurerm_api_management (sku_name = "Consumption_0") with azurerm_api_management_api / _api_operation / _api_policy, and azurerm_static_web_app.