Skip to content

Commit 74c19de

Browse files
authored
Merge pull request #296959 from craigshoemaker/aca/functions
[Container Apps] New: Azure Functions usage
2 parents 6aa12d9 + 82121fe commit 74c19de

File tree

4 files changed

+302
-2
lines changed

4 files changed

+302
-2
lines changed

articles/container-apps/TOC.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
href: storage-mounts.md
136136
- name: Create an Azure Files storage mount
137137
href: storage-mounts-azure-files.md
138+
- name: Use Azure Functions
139+
items:
140+
- name: Overview
141+
href: functions-overview.md
142+
- name: Create a Functions app
143+
href: functions-usage.md
138144
- name: Use dynamic sessions
139145
items:
140146
- name: Code interpreter sessions
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
title: Azure Functions on Azure Container Apps overview
3+
description: Learn how Azure Functions works with autoscaling rules in Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: azure-container-apps
7+
ms.topic: how-to
8+
ms.date: 04/07/2025
9+
ms.author: cshoe
10+
---
11+
12+
# Azure Functions on Azure Container Apps overview
13+
14+
Azure Functions provides integrated support for developing, deploying, and managing containerized function apps on Azure Container Apps. Use Azure Container Apps for your Functions apps when you need to run in the same environment as other microservices, APIs, websites, workflows, or any container hosted programs.
15+
16+
Container Apps hosting lets you run your functions in a fully supported and managed, container-based environment with built-in support for open-source monitoring, mTLS, Dapr, and Kubernetes Event-driven Autoscaling (KEDA).
17+
18+
As an integrated feature on Azure Container Apps, you can deploy Azure Functions images directly onto Azure Container Apps using the `Microsoft.App` resource provider by setting `kind=functionapp` when calling `az containerapp create`. Apps created this way have access to all Azure Container Apps features.
19+
20+
This article shows you how to create and deploy an Azure Functions app that runs within Azure Container Apps. You learn how to:
21+
22+
- Set up a containerized Functions app with preconfigured auto scaling rules
23+
- Deploy your application using either the Azure portal or Azure CLI
24+
- Verify your deployed function with an HTTP trigger
25+
26+
By running Functions in Container Apps, you benefit from automatic scaling, easy configuration, and a fully managed container environment—all without having to manage the underlying infrastructure yourself.
27+
28+
## Scenarios
29+
30+
Azure Functions on Container Apps provide a versatile combination of services to meet the needs of your applications. The following scenarios are representative of the types of situations where paring Azure Container Apps with Azure Functions gives you the control and scaling features you need.
31+
32+
- **Line-of-business APIs**: Package custom libraries, packages, and APIs with Functions for line-of-business applications.
33+
34+
- **Migration support**: Migration of on-premises legacy and/or monolith applications to cloud native microservices on containers.
35+
36+
- **Event-driven architecture**: Supports event-driven applications for workloads already running on Azure Container Apps.
37+
38+
- **Serverless workloads**: Serverless workload processing of videos, images, transcripts, or any other processing intensive tasks that required GPU compute resources.
39+
40+
## Event-driven scaling
41+
42+
All Functions triggers are available in your containerized Functions app. However, only the following triggers can dynamically scale (from zero instances) based on received events when running in a Container Apps environment:
43+
44+
- Azure Event Grid
45+
- Azure Event Hubs
46+
- Azure Blob Storage (event-based)
47+
- Azure Queue Storage
48+
- Azure Service Bus
49+
- Durable Functions (MSSQL storage provider)
50+
- HTTP
51+
- Kafka
52+
- Timer
53+
54+
Azure Functions on Container Apps are designed to configure the scale parameters and rules as per the event target. You don't need to worry about configuring the KEDA scaled objects. You can still set minimum and maximum replica count when creating or modifying your function app.
55+
56+
You can write your function code in any [language stack supported](/azure/azure-functions/supported-languages?tabs=isolated-process%2Cv4&pivots=programming-language-csharp) by Azure Functions. You can use the same Functions triggers and bindings with event-driven scaling.
57+
58+
## Managed identity authorization
59+
60+
To adhere to security best practices, connect to remote services using Microsoft Entra authentication and managed identity authorization.
61+
62+
Managed identities are available for the following connections:
63+
64+
- [Default storage account](/azure/azure-functions/functions-reference) (AzureWebJobsStorage)
65+
- [Azure Container Registry](/azure/azure-functions/functions-deploy-container-apps?tabs=acr): When running in Container Apps, you can use Microsoft Entra ID with managed identities for all binding extensions that support managed identities. Currently, only these binding extensions support event-driven scaling when using managed identity authentication:
66+
- Azure Event Hubs
67+
- Azure Queue Storage
68+
- Azure Service Bus
69+
70+
For other bindings, use fixed replicas when using managed identity authentication. For more information, see the [Functions developer guide](/azure/azure-functions/functions-reference).
71+
72+
## Application logging
73+
74+
You can monitor your containerized function app hosted in Container Apps using Azure Monitor Application Insights in the same way you do with apps hosted by Azure Functions. For more information, see [Monitor Azure Functions](/azure/azure-functions/monitor-functions).
75+
76+
For bindings that support event-driven scaling, scale events are logged as `FunctionsScalerInfo` and `FunctionsScalerError` events in your Log Analytics workspace. For more information, see [Application Logging in Azure Container Apps](./logging.md).
77+
78+
## Next steps
79+
80+
> [!div class="nextstepaction"]
81+
> [Use Azure Functions in Azure Container Apps](functions-usage.md)
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
---
2+
title: Create an Azure Functions app with auto scaling rules on Azure Container Apps
3+
description: Learn to create an Azure Functions app preconfigured with auto scaling rules in Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: azure-container-apps
7+
ms.topic: how-to
8+
ms.date: 04/07/2025
9+
ms.author: cshoe
10+
zone_pivot_groups: azure-cli-or-portal
11+
---
12+
13+
# Use Azure Functions in Azure Container Apps
14+
15+
This article shows you how to create an [Azure Functions app in Azure Container Apps](functions-overview.md), complete with preconfigured autoscaling rules.
16+
17+
:::zone pivot="azure-portal"
18+
19+
## Prerequisites
20+
21+
| Resource | Description |
22+
|---|---|
23+
| Azure account | An Azure account with an active subscription.<br><br>If you don't have one, you [can create one for free](https://azure.microsoft.com/free/). |
24+
| Azure Storage account | A [blob storage account](/azure/storage/common/storage-account-create?tabs=azure-portal) to store state for your Azure Functions. |
25+
| Azure Application Insights | An instance of [Azure Application Insights](/azure/azure-monitor/app/create-workspace-resource?tabs=portal) to collect data about your container app. |
26+
27+
## Create a Functions app
28+
29+
The following steps show you how to use a sample container image to create your container app. If you want to use this procedure with a custom container image, see [Create your first Azure Function on Azure Container Apps](https://github.com/Azure/azure-functions-on-container-apps/blob/main/README.md#create-your-first-azure-function-on-azure-container-apps) and [Functions in containers](/azure/azure-functions/functions-container-apps-hosting).
30+
31+
1. Go to the Azure portal and search for **Container Apps** in the search bar.
32+
33+
1. Select **Container Apps**.
34+
35+
1. Select **Create**.
36+
37+
1. Select **Container App**
38+
39+
1. In the *Basics* section, enter the following values.
40+
41+
Under *Project details*:
42+
43+
| Property | Value |
44+
|---|---|
45+
| Subscription | Select your Azure subscription. |
46+
| Resource group | Select **Create new resource group**, name it **my-aca-functions-group**, and select **OK**. |
47+
| Container app name | Enter **my-aca-functions-app**. |
48+
49+
1. Next to *Optimize for Azure Functions* check the checkbox.
50+
51+
1. Under *Container Apps environment* enter:
52+
53+
| Property | Value |
54+
|---|---|
55+
| Region | Select a region closest to you. |
56+
| Container Apps environment | Select **Create new environment**. |
57+
58+
1. In the environment setup window, enter:
59+
60+
| Property | Value |
61+
|---|---|
62+
| Environment name | Enter **my-aca-functions-environment** |
63+
| Zone redundancy | Select **Disabled**. |
64+
65+
1. Select **Create** to save your values.
66+
67+
1. Select **Next: Container** to switch to the *Container* section.
68+
69+
1. Next to *Use quickstart image*, leave this box unchecked.
70+
71+
1. Under the *Container details* section, enter the following values.
72+
73+
| Property | Value |
74+
|---|---|
75+
| Name | This box is prefilled with your selection in the last section. |
76+
| Image source | Select **Docker Hub or other registries** |
77+
| Subscription | Select your subscription. |
78+
| Image type | Select **Public**. |
79+
| Registry login server | Enter **mcr.microsoft.com** |
80+
| Image and tag | Enter **azure-functions/dotnet8-quickstart-demo:1.0** |
81+
82+
1. Under *Environment variables* enter values for the following variables:
83+
84+
- `AzureWebJobsStorage`
85+
- `APPINSIGHTS_INSTRUMENTATIONKEY` or `APPLICATIONINSIGHTS_CONNECTION_STRING`
86+
87+
Enter either Managed identity or connection string values for these variables. Managed Identity is recommended.
88+
89+
The `AzureWebJobsStorage` variable is a required Azure Storage account connection string for Azure Functions. This storage account stores function execution logs, manage triggers and bindings, and maintains state for durable functions.
90+
91+
Application Insights is a monitoring and diagnostic service that provides insights into the performance and usage of your Azure Functions. This monitoring helps you track request rates, response times, failure rates, and other metrics.
92+
93+
> [!TIP]
94+
> By default, a containerized function app monitors port `80` for incoming requests. If your app uses a different port, use the `WEBSITES_PORT` application setting to change the default port.
95+
96+
1. Select **Next > Ingress** to switch to the Ingress section and enter the following values.
97+
98+
| Property | Value |
99+
|---|---|
100+
| Ingress | Select the **Enabled** checkbox to enable ingress. |
101+
| Ingress traffic | Select **Accepting traffic from anywhere**. |
102+
| Ingress type | Select **HTTP**. |
103+
| Target port | Enter **80**. |
104+
105+
1. Select **Review + Create**.
106+
107+
1. Select **Create**.
108+
109+
1. Once the deployment is complete, select **Go to resource**.
110+
111+
1. From the *Overview* page, select the link next to *Application URL* to open the application in a new browser tab.
112+
113+
1. Append `/api/HttpExample` to the end of the URL.
114+
115+
A message stating "HTTP trigger function processed a request" is returned in the browser.
116+
117+
:::zone-end
118+
119+
:::zone pivot="azure-cli"
120+
121+
## Prerequisites
122+
123+
- An Azure account with an active subscription.
124+
- If you don't have one, you [can create one for free](https://azure.microsoft.com/free/).
125+
- Install the [Azure CLI](/cli/azure/install-azure-cli).
126+
127+
## Create a Functions App
128+
129+
To sign in to Azure from the CLI, run the following command and follow the prompts to complete the authentication process.
130+
131+
1. Sign in to Azure.
132+
133+
```azurecli
134+
az login
135+
```
136+
137+
1. To ensure you're running the latest version of the CLI, run the upgrade command.
138+
139+
```azurecli
140+
az upgrade
141+
```
142+
143+
1. Install or update the Azure Container Apps extension for the CLI.
144+
145+
If you receive errors about missing parameters when you run `az containerapp` commands in Azure CLI or cmdlets from the `Az.App` module in PowerShell, be sure you have the latest version of the Azure Container Apps extension installed.
146+
147+
```azurecli
148+
az extension add --name containerapp --upgrade
149+
```
150+
151+
Now that the current extension or module is installed, register the `Microsoft.App` and `Microsoft.OperationalInsights` namespaces.
152+
153+
```azurecli
154+
az provider register --namespace Microsoft.App
155+
```
156+
157+
```azurecli
158+
az provider register --namespace Microsoft.OperationalInsights
159+
```
160+
161+
1. Create environment variables.
162+
163+
```bash
164+
RESOURCE_GROUP_NAME="my-aca-functions-group"
165+
CONTAINER_APP_NAME="my-aca-functions-app"
166+
ENVIRONMENT_NAME="my-aca-functions-environment"
167+
LOCATION="westus"
168+
```
169+
170+
1. Create a resource group.
171+
172+
```azurecli
173+
az group create \
174+
--name $RESOURCE_GROUP_NAME \
175+
--location $LOCATION \
176+
--output none
177+
```
178+
179+
1. Create the Container Apps environment.
180+
181+
```azurecli
182+
az containerapp env create \
183+
--name $ENVIRONMENT_NAME \
184+
--resource-group $RESOURCE_GROUP_NAME \
185+
--location $LOCATION \
186+
--output none
187+
```
188+
189+
1. Create an Azure Functions container app.
190+
191+
```azurecli
192+
az containerapp create \
193+
--resource-group $RESOURCE_GROUP_NAME \
194+
--name $CONTAINER_APP_NAME \
195+
--environment $ENVIRONMENT_NAME \
196+
--image mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:1.0 \
197+
--ingress external \
198+
--target-port 80 \
199+
--kind functionapp \
200+
--query properties.outputs.fqdn
201+
```
202+
203+
This command returns the URL of your Functions app. Copy this URL and paste it into a web browser.
204+
205+
1. Append `/api/HttpExample` to the end of the URL.
206+
207+
A message stating "HTTP trigger function processed a request" is returned in the browser.
208+
209+
:::zone-end
210+
211+
## Related content
212+
213+
- [Create your first containerized functions](/azure/azure-functions/functions-deploy-container-apps)

includes/container-apps-create-cli-steps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
ms.service: azure-container-apps
33
ms.topic: include
44
ms.date: 02/03/2025
5-
author: v1212
6-
ms.author: wujia
5+
author: craigshoemaker
6+
ms.author: cshoe
77
---
88

99
## Setup

0 commit comments

Comments
 (0)