Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows you how to create an Azure Functions app in Azure Container Apps, complete with preconfigured autoscaling rules.
Prerequisites
Resource | Description |
---|---|
Azure account | An Azure account with an active subscription. If you don't have one, you can create one for free. |
Azure Storage account | A blob storage account to store state for your Azure Functions. |
Azure Application Insights | An instance of Azure Application Insights to collect data about your container app. |
Create a Functions app
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 and Functions in containers.
Go to the Azure portal and search for Container Apps in the search bar.
Select Container Apps.
Select Create.
Select Container App
In the Basics section, enter the following values.
Under Project details:
Property Value Subscription Select your Azure subscription. Resource group Select Create new resource group, name it my-aca-functions-group, and select OK. Container app name Enter my-aca-functions-app. Next to Optimize for Azure Functions check the checkbox.
Under Container Apps environment enter:
Property Value Region Select a region closest to you. Container Apps environment Select Create new environment. In the environment setup window, enter:
Property Value Environment name Enter my-aca-functions-environment Zone redundancy Select Disabled. Select Create to save your values.
Select Next: Container to switch to the Container section.
Next to Use quickstart image, leave this box unchecked.
Under the Container details section, enter the following values.
Property Value Name This box is prefilled with your selection in the last section. Image source Select Docker Hub or other registries Subscription Select your subscription. Image type Select Public. Registry login server Enter mcr.microsoft.com Image and tag Enter azure-functions/dotnet8-quickstart-demo:1.0 Under Environment variables enter values for the following variables:
AzureWebJobsStorage
APPINSIGHTS_INSTRUMENTATIONKEY
orAPPLICATIONINSIGHTS_CONNECTION_STRING
Enter either Managed identity or connection string values for these variables. Managed Identity is recommended.
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.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.
Tip
By default, a containerized function app monitors port
80
for incoming requests. If your app uses a different port, use theWEBSITES_PORT
application setting to change the default port.Select Next > Ingress to switch to the Ingress section and enter the following values.
Property Value Ingress Select the Enabled checkbox to enable ingress. Ingress traffic Select Accepting traffic from anywhere. Ingress type Select HTTP. Target port Enter 80. Select Review + Create.
Select Create.
Once the deployment is complete, select Go to resource.
From the Overview page, select the link next to Application URL to open the application in a new browser tab.
Append
/api/HttpExample
to the end of the URL.A message stating "HTTP trigger function processed a request" is returned in the browser.
Prerequisites
- An Azure account with an active subscription.
- If you don't have one, you can create one for free.
- Install the Azure CLI.
Create a Functions App
To sign in to Azure from the CLI, run the following command and follow the prompts to complete the authentication process.
Sign in to Azure.
az login
To ensure you're running the latest version of the CLI, run the upgrade command.
az upgrade
Install or update the Azure Container Apps extension for the CLI.
If you receive errors about missing parameters when you run
az containerapp
commands in Azure CLI or cmdlets from theAz.App
module in PowerShell, be sure you have the latest version of the Azure Container Apps extension installed.az extension add --name containerapp --upgrade
Now that the current extension or module is installed, register the
Microsoft.App
andMicrosoft.OperationalInsights
namespaces.az provider register --namespace Microsoft.App
az provider register --namespace Microsoft.OperationalInsights
Create environment variables.
RESOURCE_GROUP_NAME="my-aca-functions-group" CONTAINER_APP_NAME="my-aca-functions-app" ENVIRONMENT_NAME="my-aca-functions-environment" LOCATION="westus"
Create a resource group.
az group create \ --name $RESOURCE_GROUP_NAME \ --location $LOCATION \ --output none
Create the Container Apps environment.
az containerapp env create \ --name $ENVIRONMENT_NAME \ --resource-group $RESOURCE_GROUP_NAME \ --location $LOCATION \ --output none
Create an Azure Functions container app.
az containerapp create \ --resource-group $RESOURCE_GROUP_NAME \ --name $CONTAINER_APP_NAME \ --environment $ENVIRONMENT_NAME \ --image mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:1.0 \ --ingress external \ --target-port 80 \ --kind functionapp \ --query properties.outputs.fqdn
This command returns the URL of your Functions app. Copy this URL and paste it into a web browser.
Append
/api/HttpExample
to the end of the URL.A message stating "HTTP trigger function processed a request" is returned in the browser.