Skip to content

Commit cea7202

Browse files
authored
Merge pull request #205116 from ggailey777/powershell
[Functions] Azure PowerShell create resources example scripts article
2 parents 9ee2dc3 + 30a386f commit cea7202

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

articles/azure-functions/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163
items:
164164
- name: GitHub deployment
165165
href: ./scripts/functions-cli-create-function-app-github-continuous.md
166+
- name: Azure PowerShell
167+
href: create-resources-azure-powershell.md
166168
- name: Concepts
167169
items:
168170
- name: Best practices
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: Create function app resources in Azure using PowerShell
3+
description: Azure PowerShell scripts that show you how to create the Azure resources required to host your functions code in Azure.
4+
ms.topic: sample
5+
ms.date: 07/18/2022
6+
---
7+
# Create function app resources in Azure using PowerShell
8+
9+
The Azure PowerShell example scripts in this article create function apps and other resources required to host your functions in Azure. A function app provides an execution context in which your functions are executed. All functions running in a function app share the same resources and connections, and they're all scaled together.
10+
11+
After the resources are created, you can deploy your project files to the new function app. To learn more, see [Deployment methods](functions-deployment-technologies.md#deployment-methods).
12+
13+
Every function app requires your PowerShell scripts to create the following resources:
14+
15+
| Resource | cmdlet | Description |
16+
| --- | --- | --- |
17+
| Resource group | [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup) | Creates a [resource group](../azure-resource-manager/management/overview.md) in which you'll create your function app. |
18+
| Storage account | [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount) | Creates a [storage account](../storage/common/storage-account-create.md) used by your function app. Storage account names must be between 3 and 24 characters in length and can contain numbers and lowercase letters only. You can also use an existing account, which must meet the [storage account requirements](storage-considerations.md#storage-account-requirements). |
19+
| App Service plan | [New-AzFunctionAppPlan](/powershell/module/az.functions/new-azfunctionappplan) | Explicitly creates a hosting plan, which defines how resources are allocated to your function app. Used only when hosting in a Premium or Dedicated plan. You won't use this cmdlet when hosting in a serverless [Consumption plan](consumption-plan.md), since Consumption plans are created when you run `New-AzFunctionApp`. For more information, see [Azure Functions hosting options](functions-scale.md). |
20+
| Function app | [New-AzFunctionApp](/powershell/module/az.functions/new-azfunctionapp) | Creates the function app using the required resources. The `-Name` parameter must be a globally unique name across all of Azure App Service. Valid characters in `-Name` are `a-z` (case insensitive), `0-9`, and `-`. Most examples create a function app that supports C# functions. You can change the language by using the `-Runtime` parameter, with supported values of `DotNet`, `Java`, `Node`, `PowerShell`, and `Python`. Use the `-RuntimeVersion` to choose a [specific language version](supported-languages.md#languages-by-runtime-version). |
21+
22+
This article contains the following examples:
23+
24+
* [Create a serverless function app for C#](#create-a-serverless-function-app-for-c)
25+
* [Create a serverless function app for Python](#create-a-serverless-function-app-for-python)
26+
* [Create a scalable function app in a Premium plan](#create-a-scalable-function-app-in-a-premium-plan)
27+
* [Create a function app in a Dedicated plan](#create-a-function-app-in-a-dedicated-plan)
28+
* [Create a function app with a named Storage connection](#create-a-function-app-with-a-named-storage-connection)
29+
* [Create a function app with an Azure Cosmos DB connection](#create-a-function-app-with-an-azure-cosmos-db-connection)
30+
* [Create a function app with an Azure Cosmos DB connection](#create-a-function-app-with-an-azure-cosmos-db-connection)
31+
* [Create a function app with continuous deployment](#create-a-function-app-with-continuous-deployment)
32+
* [Create a serverless Python function app and mount file share](#create-a-serverless-python-function-app-and-mount-file-share)
33+
34+
[!INCLUDE [azure-powershell-requirements](../../includes/azure-powershell-requirements.md)]
35+
36+
[!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)]
37+
38+
## Create a serverless function app for C#
39+
40+
The following script creates a serverless C# function app in the default Consumption plan:
41+
42+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-consumption/create-function-app-consumption.ps1" id="FullScript":::
43+
44+
## Create a serverless function app for Python
45+
46+
The following script creates a serverless Python function app in a Consumption plan:
47+
48+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-consumption-python/create-function-app-consumption-python.ps1" id="FullScript":::
49+
50+
## Create a scalable function app in a Premium plan
51+
52+
The following script creates a C# function app in an Elastic Premium plan that supports [dynamic scale](event-driven-scaling.md):
53+
54+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-premium-plan/create-function-app-premium-plan.ps1" id="FullScript":::
55+
56+
## Create a function app in a Dedicated plan
57+
58+
The following script creates a function app hosted in a Dedicated plan, which isn't scaled dynamically by Functions:
59+
60+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-app-service-plan/create-function-app-app-service-plan.ps1" id="FullScript":::
61+
62+
## Create a function app with a named Storage connection
63+
64+
The following script creates a function app with a named Storage connection in application settings:
65+
66+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-connect-to-storage/create-function-app-connect-to-storage-account.ps1" id="FullScript":::
67+
68+
## Create a function app with an Azure Cosmos DB connection
69+
70+
The following script creates a function app and a connected Azure Cosmos DB account:
71+
72+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/create-function-app-connect-to-cosmos-db/create-function-app-connect-to-cosmos-db.ps1" id="FullScript":::
73+
74+
## Create a function app with continuous deployment
75+
76+
The following script creates a function app that has continuous deployment configured to publish from a public GitHub repository:
77+
78+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/deploy-function-app-with-function-github-continuous/deploy-function-app-with-function-github-continuous.ps1" id="FullScript":::
79+
80+
## Create a serverless Python function app and mount file share
81+
82+
The following script creates a Python function app on Linux and creates and mounts an external Azure Files share:
83+
84+
:::code language="azurepowershell-interactive" source="~/functions-docs-powershell/azure-functions/functions-cli-mount-files-storage-linux/functions-cli-mount-files-storage-linux.ps1" id="FullScript":::
85+
86+
Mounted file shares are only supported on Linux. For more information, see [Mount file shares](storage-considerations.md#mount-file-shares).
87+
88+
[!INCLUDE [powershell-samples-clean-up](../../includes/powershell-samples-clean-up.md)]
89+
90+
## Next steps
91+
92+
For more information on Azure PowerShell, see [Azure PowerShell documentation](/powershell/azure).

articles/azure-functions/storage-considerations.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,26 @@ Because Functions use Azure Files during parts of the the dynamic scale-out proc
109109

110110
_This functionality is current only available when running on Linux._
111111

112-
You can mount existing Azure Files shares to your Linux function apps. By mounting a share to your Linux function app, you can leverage existing machine learning models or other data in your functions. You can use the [`az webapp config storage-account add`](/cli/azure/webapp/config/storage-account#az-webapp-config-storage-account-add) command to mount an existing share to your Linux function app.
112+
You can mount existing Azure Files shares to your Linux function apps. By mounting a share to your Linux function app, you can leverage existing machine learning models or other data in your functions. You can use the following command to mount an existing share to your Linux function app.
113+
114+
# [Azure CLI](#tab/azure-cli)
115+
116+
[`az webapp config storage-account add`](/cli/azure/webapp/config/storage-account#az-webapp-config-storage-account-add)
113117

114118
In this command, `share-name` is the name of the existing Azure Files share, and `custom-id` can be any string that uniquely defines the share when mounted to the function app. Also, `mount-path` is the path from which the share is accessed in your function app. `mount-path` must be in the format `/dir-name`, and it can't start with `/home`.
115119

116120
For a complete example, see the scripts in [Create a Python function app and mount a Azure Files share](scripts/functions-cli-mount-files-storage-linux.md).
117121

122+
# [Azure PowerShell](#tab/azure-powershell)
123+
124+
[`New-AzWebAppAzureStoragePath`](/powershell/module/az.websites/new-azwebappazurestoragepath)
125+
126+
In this command, `-ShareName` is the name of the existing Azure Files share, and `-MountPath` is the path from which the share is accessed in your function app. `-MountPath` must be in the format `/dir-name`, and it can't start with `/home`. After you create the path, use the `-AzureStoragePath` parameter of [`Set-AzWebApp`](/powershell/module/az.websites/set-azwebapp) to add the share to the app.
127+
128+
For a complete example, see the script in [Create a serverless Python function app and mount file share](create-resources-azure-powershell.md#create-a-serverless-python-function-app-and-mount-file-share).
129+
130+
---
131+
118132
Currently, only a `storage-type` of `AzureFiles` is supported. You can only mount five shares to a given function app. Mounting a file share may increase the cold start time by at least 200-300ms, or even more when the storage account is in a different region.
119133

120134
The mounted share is available to your function code at the `mount-path` specified. For example, when `mount-path` is `/path/to/mount`, you can access the target directory by file system APIs, as in the following Python example:

0 commit comments

Comments
 (0)