Skip to content

Latest commit

 

History

History
176 lines (136 loc) · 12.7 KB

File metadata and controls

176 lines (136 loc) · 12.7 KB
page_type sample
languages
azurecli
products
azure
azure-clis
azure-functions
name Azure Functions sample scripts
url-fragment
description These scripts demonstrate how to create and manage Azure Functions resources using the Azure CLI.

Azure Functions: Azure CLI sample scripts

These end-to-end Azure CLI scripts help you learn how to provision and manage the Azure resources required by Azure Functions. You must use the Azure Functions Core Tools to create actual Azure Functions code projects from the command line on your local computer and deploy code to these Azure resources.

For a complete end-to-end example of developing and deploying from the command line using both Core Tools and the Azure CLI, see one of these language-specific command line quickstarts.

The scripts in this directory demonstrate working with Azure Functions using the Azure CLI reference commands.

Prerequisites

Run a script

Each script is self-contained and uses random identifiers to create uniquely named resources. To run a script:

  1. Open Azure Cloud Shell or your local Bash terminal signed in to Azure.

  2. Navigate to the folder that contains the script you want to run.

  3. Run the script directly:

    bash <script-name>.sh

The scripts set variables at the top for resource names, locations, and SKUs. You can modify these before running.

Clean up resources

Every script creates resources in a new resource group. After you're done, you can delete all the resources created by a script by deleting its resource group:

az group delete --name $resourceGroup --yes --no-wait

Each script also includes a commented-out cleanup command at the end that you can uncomment to enable automatic cleanup.

Sample scripts

Script Description
Create a function app
create-function-app-flex-consumption.sh Creates a function app in a Flex Consumption plan with a user-assigned managed identity. This is the recommended serverless hosting plan.
create-function-app-consumption.sh Creates a function app in a Consumption plan.
create-function-app-premium-plan.sh Creates a function app in a Premium (Elastic Premium) plan.
create-function-app-app-service-plan.sh Creates a function app in a dedicated App Service plan.
Connect to services
create-function-app-connect-to-storage-account.sh Creates a function app in a Flex Consumption plan and connects it to a storage account using managed identity.
create-function-app-connect-to-cosmos-db.sh Creates a function app in a Flex Consumption plan and connects it to Azure Cosmos DB using managed identity and RBAC.
connect-azure-openai-resources.sh Creates a function app in a Flex Consumption plan and connects it to Azure OpenAI using managed identity.
functions-cli-mount-files-storage-linux.sh Creates a Linux function app and mounts an Azure Files share, which lets you leverage existing data or machine learning models in your functions.
Secure networking
create-function-app-vnet-storage.sh Creates a function app in a Flex Consumption plan with VNet integration and restricts the storage account behind private endpoints so it's only accessible from inside the virtual network.
create-function-app-private-endpoint.sh Creates a function app in a Flex Consumption plan with an inbound private endpoint, restricting the function app's HTTP endpoints to only be callable from inside the virtual network.
Deploy code
deploy-function-app-with-function-github-continuous.sh Creates a function app in a Consumption plan and deploys code from a public GitHub repository.

CLI command reference

The following table lists the Azure CLI commands used across these sample scripts.

Resource management

Command Notes
az group create Creates a resource group to contain all script resources.
az group delete Deletes a resource group and all contained resources.

Storage

Command Notes
az storage account create Creates an Azure Storage account.
az storage account show Gets storage account details, including the resource ID for role assignments.
az storage account update Updates storage account properties, such as disabling public network access.
az storage share create Creates a file share in Azure Files.
az storage directory create Creates a directory in an Azure Files share.

Function apps

Command Notes
az functionapp create Creates a function app in a Consumption, Flex Consumption, Premium, or Dedicated plan.
az functionapp plan create Creates a Premium or App Service hosting plan for a function app.
az functionapp config appsettings set Creates or updates application settings in a function app.
az functionapp config appsettings delete Removes application settings from a function app.
az functionapp show Gets the details of a function app, including the resource ID.

Identity and access

Command Notes
az identity create Creates a user-assigned managed identity.
az identity show Gets the properties of a managed identity, including the client ID.
az role assignment create Assigns an Azure RBAC role to a managed identity or user account.
az ad signed-in-user show Gets the object ID of the current signed-in Azure account.

Monitoring

Command Notes
az monitor app-insights component show Gets the Application Insights resource for a function app.
az extension add Installs CLI extensions, such as the application-insights extension.

Azure Cosmos DB

Command Notes
az cosmosdb create Creates an Azure Cosmos DB account.
az cosmosdb show Gets account details, including the document endpoint.
az cosmosdb sql database create Creates a database in a Cosmos DB account.
az cosmosdb sql container create Creates a container in a Cosmos DB SQL database.
az cosmosdb sql role assignment create Assigns a Cosmos DB data-plane RBAC role to a principal.

Azure OpenAI

Command Notes
az cognitiveservices account create Creates an Azure OpenAI (Cognitive Services) resource.

Networking

Command Notes
az network vnet create Creates a virtual network.
az network vnet subnet create Creates a subnet, optionally with a delegation for Functions VNet integration.
az network private-endpoint create Creates a private endpoint for a storage account or function app.
az network private-dns zone create Creates a private DNS zone for private endpoint name resolution.
az network private-dns link vnet create Links a private DNS zone to a virtual network.
az network private-endpoint dns-zone-group create Configures a private endpoint to register DNS records in a private DNS zone.
az resource update Updates a resource property, such as disabling public network access on a function app.

Other resources