|
| 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) |
0 commit comments