Nóta
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað aðskrá þig inn eða breyta skráasöfnum.
Aðgangur að þessari síðu krefst heimildar. Þú getur prófað að breyta skráasöfnum.
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 function app in Azure Container Apps.
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 k8se/quickstart-functions:latest Under Environment variables, enter values for the following variables:
AzureWebJobsStorageAPPINSIGHTS_INSTRUMENTATIONKEYorAPPLICATIONINSIGHTS_CONNECTION_STRING
Enter either Managed identity or connection string values for these variables. Managed Identity is recommended.
The
AzureWebJobsStoragevariable 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.
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/HttpExampleto 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 loginTo ensure you're running the latest version of the CLI, run the upgrade command.
az upgradeInstall or update the Azure Container Apps extension for the CLI.
If you receive errors about missing parameters when you run
az containerappcommands in Azure CLI or cmdlets from theAz.Appmodule in PowerShell, be sure you have the latest version of the Azure Container Apps extension installed.az extension add --name containerapp --allow-preview true --upgradeNow that the current extension or module is installed, register the
Microsoft.AppandMicrosoft.OperationalInsightsnamespaces.az provider register --namespace Microsoft.Appaz provider register --namespace Microsoft.OperationalInsightsCreate environment variables.
RESOURCE_GROUP_NAME="my-aca-functions-group" CONTAINER_APP_NAME="my-aca-functions-app" ENVIRONMENT_NAME="my-aca-functions-environment" LOCATION="westus" STORAGE_ACCOUNT_NAME="storage-account-name" STORAGE_ACCOUNT_SKU="storage-account-sku" APPLICATION_INSIGHTS_NAME="application-insights-name"Create a resource group.
az group create \ --name $RESOURCE_GROUP_NAME \ --location $LOCATION \ --output noneCreate the Container Apps environment.
az containerapp env create \ --name $ENVIRONMENT_NAME \ --resource-group $RESOURCE_GROUP_NAME \ --location $LOCATION \ --output noneCreate the Storage Account
az storage account create \ --name $STORAGE_ACCOUNT_NAME \ --resource-group $RESOURCE_GROUP \ --location $LOCATION \ --sku $STORAGE_ACCOUNT_SKUAcquire Storage Account Connection String
$STORAGE_ACCOUNT_CONNECTION_STRING = az storage account show-connection-string \ --name $STORAGE_ACCOUNT_NAME \ --resource-group $RESOURCE_GROUP \ --query connectionString \ --output tsvCreate Azure Applications Insights
az monitor app-insights component create \ --app $APPLICATION_INSIGHTS_NAME \ --location $LOCATION \ --resource-group $RESOURCE_GROUP \ --application-type webAcquire application Insights Connection string
$APPLICATION_INSIGHTS_CONNECTION_STRING = az monitor app-insights component show \ --app $APPLICATION_INSIGHTS_NAME \ --resource-group $RESOURCE_GROUP \ --query connectionString \ --output tsvCreate 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.fqdnThis command returns the URL of your Functions app. Copy this URL and paste it into a web browser.
Create an Azure Functions container app with --revisions-mode multiple for multirevision scenario
az containerapp create \ --name $CONTAINERAPP_NAME \ --resource-group $RESOURCE_GROUP \ --environment $CONTAINERAPPS_ENVIRONMENT \ --image mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:1.0 \ --target-port 80 \ --ingress external \ --kind functionapp \ --workload-profile-name $WORKLOAD_PROFILE_NAME \ --env-vars AzureWebJobsStorage="$STORAGE_ACCOUNT_CONNECTION_STRING" APPLICATIONINSIGHTS_CONNECTION_STRING="$APPLICATION_INSIGHTS_CONNECTION_STRING"For multirevision scenario, upgrade the containerapp and split traffic
az containerapp update \ --resource-group $RESOURCE_GROUP \ --name $CONTAINERAPP_NAME \ --image mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:latest az containerapp ingress traffic set -resource-group \ --name $CONTAINERAPP_NAME \ --resource-group $RESOURCE_GROUP \ --revision-weight {revision1_name}=50 \ --revision-weight {revision2_name}=50Append
/api/HttpExampleto the end of the URL.A message stating "HTTP trigger function processed a request" is returned in the browser.
Manage functions
You can manage your deployed functions within Azure Container Apps using the Azure CLI. The following commands help you list, inspect, and interact with the functions running in your containerized environment.
Note
When dealing with multirevision scenarios, add the --revision <REVISION_NAME> parameter to your command to target a specific revision.
List functions
View all functions deployed in your container app:
# List all functions
az containerapp function list \
--resource-group $RESOURCE_GROUP \
--name $CONTAINERAPP_NAME
Show function details
Get detailed information about a specific function:
az containerapp function show \
--resource-group $RESOURCE_GROUP \
--name $CONTAINERAPP_NAME \
--function-name <FUNCTIONS_APP_NAME>
Monitor function invocations
Monitoring your function app is essential for understanding its performance and diagnosing issues. The following commands show you how to retrieve function URLs, trigger invocations, and view detailed telemetry and invocation summaries by using the Azure CLI.
Ensure to invoke the function few times by curl -X POST "fqdn/api/HttpExample" before calling the traces
To view invocation traces, get detailed traces of function invocations.
az containerapp function invocations traces \ --name $CONTAINERAPP_NAME \ --resource-group $RESOURCE_GROUP \ --function-name <FUNCTIONS_APP_NAME> \ --timespan 5h \ --limit 3View an invocation summary to review successful and failed invocations.
az containerapp function invocations summary \ --name $CONTAINERAPP_NAME \ --resource-group $RESOURCE_GROUP \ --function-name <FUNCTIONS_APP_NAME> \ --timespan 5h
Manage function keys
Azure Functions uses keys for authentication and authorization. You can manage the following different types of keys:
- Host keys: Access any function in the app
- Master keys: Provide administrative access
- System keys: Used by Azure services
- Function keys: Access specific functions
The following commands show you how to manage keys for the host. To run the same command for a specific Functions app, add the --function-name <FUNCTIONS_APP_NAME> parameter to your command.
List keys
Use the following commands to list host-level and function-specific keys for your Azure Functions running in Container Apps.
Note
Keep a minimum of one replica running for the following keys management commands to work.
az containerapp function keys list \
--resource-group $RESOURCE_GROUP \
--name $CONTAINERAPP_NAME \
--key-type hostKey
Show a specific key
Show the value of a specific host-level key for your function app with the following command:
az containerapp function keys show \
--resource-group $RESOURCE_GROUP \
--name $CONTAINERAPP_NAME \
--key-name <KEY_NAME> \
--key-type hostKey
Set a key
Set a specific host-level key for your function app with the following command:
az containerapp function keys set \
--resource-group $RESOURCE_GROUP \
--name $CONTAINERAPP_NAME \
--key-name <KEY_NAME> \
--key-value <KEY_VALUE> \
--key-type hostKey