Skip to content

Commit 6110e25

Browse files
Azure Docs: Azure Functions App (#581)
Co-authored-by: Brian Rinaldi <brian.rinaldi@gmail.com>
1 parent 2a610f9 commit 6110e25

1 file changed

Lines changed: 307 additions & 0 deletions

File tree

Lines changed: 307 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,307 @@
1+
---
2+
title: "Function Apps"
3+
description: Get started with Azure Function Apps on LocalStack
4+
template: doc
5+
---
6+
7+
import AzureFeatureCoverage from "../../../../components/feature-coverage/AzureFeatureCoverage";
8+
9+
## Introduction
10+
11+
Azure Function Apps are serverless compute resources that host and execute Azure Functions in response to events.
12+
They support multiple runtime environments including Python, Node.js, and .NET, and integrate with a wide range of trigger sources such as HTTP requests, queues, and timers.
13+
Function Apps are commonly used to build event-driven microservices, scheduled background jobs, and lightweight API backends. For more information, see [Introduction to Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/functions-overview).
14+
15+
LocalStack for Azure provides a local environment for building and testing applications that make use of Azure Function Apps.
16+
The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Function Apps' integration with LocalStack.
17+
18+
## Getting started
19+
20+
This guide walks you through creating a Function App backed by a Storage Account, deploying a Python HTTP-trigger function, and invoking it.
21+
22+
Launch LocalStack using your preferred method. For more information, see [Introduction to LocalStack for Azure](/azure/getting-started/). Once the container is running, enable Azure CLI interception by running:
23+
24+
```bash
25+
azlocal start-interception
26+
```
27+
28+
This command points the `az` CLI away from the public Azure management REST API and toward the LocalStack for Azure emulator API.
29+
To revert this configuration, run:
30+
31+
```bash
32+
azlocal stop-interception
33+
```
34+
35+
This reconfigures the `az` CLI to send commands to the official Azure management REST API.
36+
37+
### Create a resource group
38+
39+
Create a resource group to hold all resources created in this guide:
40+
41+
```bash
42+
az group create --name rg-func-demo --location westeurope
43+
```
44+
45+
```bash title="Output"
46+
{
47+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-func-demo",
48+
"location": "westeurope",
49+
"name": "rg-func-demo",
50+
"properties": { "provisioningState": "Succeeded" },
51+
"type": "Microsoft.Resources/resourceGroups"
52+
}
53+
```
54+
55+
### Create a storage account
56+
57+
Function Apps require a Storage Account for internal bookkeeping.
58+
59+
```bash
60+
az storage account create \
61+
--name safuncdemo \
62+
--resource-group rg-func-demo \
63+
--location westeurope \
64+
--sku Standard_LRS
65+
```
66+
67+
```bash title="Output"
68+
{
69+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-func-demo/providers/Microsoft.Storage/storageAccounts/safuncdemo",
70+
"kind": "StorageV2",
71+
"location": "westeurope",
72+
"name": "safuncdemo",
73+
"provisioningState": "Succeeded",
74+
"resourceGroup": "rg-func-demo",
75+
"sku": { "name": "Standard_LRS", "tier": "Standard" },
76+
"type": "Microsoft.Storage/storageAccounts",
77+
...
78+
}
79+
```
80+
81+
### Create a function app
82+
83+
Create a function app and associate it with the storage account and App Service plan:
84+
85+
```bash
86+
az functionapp create \
87+
--name my-func-app \
88+
--resource-group rg-func-demo \
89+
--consumption-plan-location westeurope \
90+
--runtime python \
91+
--runtime-version 3.13 \
92+
--functions-version 4 \
93+
--os-type linux \
94+
--storage-account safuncdemo
95+
```
96+
97+
```bash title="Output"
98+
{
99+
"defaultHostName": "my-func-app.azurewebsites.azure.localhost.localstack.cloud:4566",
100+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-func-demo/providers/Microsoft.Web/sites/my-func-app",
101+
"kind": "functionapp,linux",
102+
"location": "westeurope",
103+
"name": "my-func-app",
104+
"resourceGroup": "rg-func-demo",
105+
"state": "Running",
106+
"type": "Microsoft.Web/sites",
107+
...
108+
}
109+
```
110+
111+
### Configure app settings
112+
113+
Add environment variables as application settings on the function app:
114+
115+
```bash
116+
az functionapp config appsettings set \
117+
--name my-func-app \
118+
--resource-group rg-func-demo \
119+
--settings \
120+
FUNCTIONS_WORKER_RUNTIME=python \
121+
MY_CUSTOM_SETTING=hello-world
122+
```
123+
124+
```bash title="Output"
125+
[
126+
{ "name": "FUNCTIONS_WORKER_RUNTIME", "slotSetting": false, "value": "python" },
127+
{ "name": "MY_CUSTOM_SETTING", "slotSetting": false, "value": "hello-world" },
128+
{ "name": "AzureWebJobsStorage", "slotSetting": false, "value": "DefaultEndpointsProtocol=https;..." },
129+
...
130+
]
131+
```
132+
133+
### List application settings
134+
135+
List all application settings currently configured on the function app:
136+
137+
```bash
138+
az functionapp config appsettings list \
139+
--name my-func-app \
140+
--resource-group rg-func-demo
141+
```
142+
143+
```bash title="Output"
144+
[
145+
{ "name": "FUNCTIONS_WORKER_RUNTIME", "slotSetting": false, "value": "python" },
146+
{ "name": "FUNCTIONS_EXTENSION_VERSION", "slotSetting": false, "value": "~4" },
147+
{ "name": "AzureWebJobsStorage", "slotSetting": false, "value": "DefaultEndpointsProtocol=https;..." },
148+
{ "name": "MY_CUSTOM_SETTING", "slotSetting": false, "value": "hello-world" },
149+
...
150+
]
151+
```
152+
153+
### Create the function package
154+
155+
Create a directory for the function source and add the required files:
156+
157+
```bash
158+
mkdir my_func && cd my_func
159+
```
160+
161+
Create `function_app.py` with an HTTP-triggered function:
162+
163+
```python title="function_app.py"
164+
import azure.functions as func
165+
166+
app = func.FunctionApp()
167+
168+
@app.function_name(name="HelloWorld")
169+
@app.route(route="public", methods=["GET"], auth_level=func.AuthLevel.ANONYMOUS)
170+
def public(req: func.HttpRequest) -> func.HttpResponse:
171+
name = req.params.get("name", "World")
172+
return func.HttpResponse(f"Hello, {name}!")
173+
```
174+
175+
Create `host.json`:
176+
177+
```json title="host.json"
178+
{
179+
"version": "2.0"
180+
}
181+
```
182+
183+
Create `requirements.txt`:
184+
185+
```text title="requirements.txt"
186+
azure-functions
187+
```
188+
189+
Package everything into a zip archive and return to the parent directory:
190+
191+
```bash
192+
zip my_func.zip function_app.py host.json requirements.txt
193+
cd ..
194+
```
195+
196+
### Deploy function code
197+
198+
Deploy the zip package to the function app:
199+
200+
```bash
201+
az functionapp deploy \
202+
--resource-group rg-func-demo \
203+
--name my-func-app \
204+
--src-path ./my_func/my_func.zip \
205+
--type zip
206+
```
207+
208+
### Invoke an HTTP-trigger function
209+
210+
After deployment, invoke the function via its default hostname:
211+
212+
```bash
213+
curl "http://my-func-app.azurewebsites.azure.localhost.localstack.cloud:4566/api/public?name=LocalStack"
214+
```
215+
216+
```bash title="Output"
217+
Hello, LocalStack!
218+
```
219+
220+
### List and inspect function apps
221+
222+
List all function apps in the resource group in table format and retrieve the full configuration of the app:
223+
224+
```bash
225+
az functionapp list --resource-group rg-func-demo --output table
226+
```
227+
228+
```bash title="Output"
229+
Name Location State ResourceGroup DefaultHostName AppServicePlan
230+
----------- ----------- ------- --------------- ---------------------------------------------------------------- ----------------
231+
my-func-app West Europe Running rg-func-demo my-func-app.azurewebsites.azure.localhost.localstack.cloud:4566 Default1pn
232+
```
233+
234+
235+
Then retrieve the full configuration of the function app:
236+
237+
```bash
238+
az functionapp show --name my-func-app --resource-group rg-func-demo
239+
```
240+
241+
```bash title="Output"
242+
{
243+
"defaultHostName": "my-func-app.azurewebsites.azure.localhost.localstack.cloud:4566",
244+
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-func-demo/providers/Microsoft.Web/sites/my-func-app",
245+
"kind": "functionapp,linux",
246+
"location": "westeurope",
247+
"name": "my-func-app",
248+
"resourceGroup": "rg-func-demo",
249+
"state": "Running",
250+
"type": "Microsoft.Web/sites"
251+
...
252+
}
253+
```
254+
255+
### Delete and verify
256+
257+
Delete the resource and confirm it no longer appears in the list:
258+
259+
```bash
260+
az functionapp delete --name my-func-app --resource-group rg-func-demo
261+
```
262+
263+
Then list all function apps to confirm the resource group is now empty:
264+
265+
```bash
266+
az functionapp list --resource-group rg-func-demo
267+
```
268+
269+
```bash title="Output"
270+
[]
271+
```
272+
273+
## Features
274+
275+
- **Full CRUD lifecycle:** Create, read, update, and delete Function App resources using the Azure CLI or ARM API.
276+
- **App settings management:** Set and list application settings via `az functionapp config appsettings`.
277+
- **Site configuration:** Configure site properties including `linuxFxVersion`, `use32BitWorkerProcess`, and `alwaysOn`.
278+
- **Publishing credentials:** Retrieve deployment credentials via the `listPublishingCredentials` action.
279+
- **Publishing profile:** Download publish profiles via the `listPublishingProfileXmlWithSecrets` action.
280+
- **SCM access control:** Get and configure source control manager (SCM) access policy.
281+
- **Diagnostic logs:** Configure logging via `az webapp log config`.
282+
- **Consumption plan auto-provisioning:** An App Service Plan is automatically created for the Function App when using a consumption plan location.
283+
- **Docker container execution:** Actual function execution is backed by a Docker container spawned on deploy.
284+
- **HTTP trigger invocation:** HTTP-triggered functions are accessible via the default host name after deployment.
285+
- **Multiple runtimes:** Python, Node.js, and .NET function runtimes are supported for execution.
286+
287+
## Limitations
288+
289+
- **Docker required for execution:** Function code execution requires Docker to be running. Without Docker, the Function App resource can be created and managed, but code will not run.
290+
- **Durable Functions not supported:** Stateful orchestration via Durable Functions is not emulated.
291+
- **Timer and non-HTTP triggers:** Timer, Blob, Queue, Service Bus, Event Hub, Event Grid, and Cosmos DB triggers are not automatically fired by LocalStack. They must be invoked manually or by external tooling.
292+
- **Deployment slots:** Staging slots and slot swaps are not supported.
293+
- **Log streaming:** Live log streaming via `az webapp log tail` is not supported.
294+
- **Managed identities for functions:** Assigning a managed identity to a Function App is accepted at the ARM level but authentication tokens are not issued for bindings.
295+
296+
## Samples
297+
298+
The following sample demonstrates how to use Azure Function Apps with LocalStack for Azure:
299+
300+
- [Function App and Storage](https://github.com/localstack/localstack-azure-samples/samples/function-app-storage-http/dotnet/README.md)
301+
- [Function App and Front Door](https://github.com/localstack/localstack-azure-samples/samples/function-app-front-door/python/README.md)
302+
- [Function App and Managed Identities](https://github.com/localstack/localstack-azure-samples/samples/function-app-managed-identity/python/README.md)
303+
- [Function App and Service Bus](https://github.com/localstack/localstack-azure-samples/samples/function-app-service-bus/dotnet/README.md)
304+
305+
## API Coverage
306+
307+
<AzureFeatureCoverage service="Microsoft.Web" client:load />

0 commit comments

Comments
 (0)