使用 Powershell 创建基于消耗的应用服务计划

2023-11-22

我找到了这个答案question

有谁知道如何创建一个消耗Azure 的应用程序服务计划?

当我查看属性时(使用https://resources.azure.com/)我(由 Gui)制作的一个,我看到以下属性;

  },
  "sku": {
    "name": "Y1",
    "tier": "Dynamic",
    "size": "Y1",
    "family": "Y",
    "capacity": 0
  }


{
  "id": "/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Web/serverfarms/MyHandMadeConsumptionAppServicePlan",
  "name": "MyHandMadeConsumptionAppServicePlan",
  "type": "Microsoft.Web/serverfarms",
  "kind": "functionapp",
  "location": "East US",

但如果我尝试(重要的部分是“-Tier Dynamic”)

$plan = New-AzureRmAppServicePlan -Name 'MyPowershellCreatedAppServicePlan' -ResourceGroupName 'MyResourceGroup' -Location 'PickALocation' -Tier Dynamic

我得到例外:

异常 - + 无法验证参数“Tier”的参数。这 参数“Dynamic”不属于该集合 指定的“免费、共享、基本、标准、高级、高级V2” 验证集属性。提供集合中的参数,然后 再次尝试该命令。


天哪,路易丝。

这已经折磨了我三天了。我终于找到了一些帮助(我提到的网址)。

看起来(当前)无法使用 New-AzureRmAppServicePlan 来完成此任务。

但您可以退回到更通用的 New-AzureRmResource。

我终于开始工作的代码:

function SafeCreateAppServicePlan(
    [Parameter(Mandatory = $true)]
    [System.String]$location, 
    [Parameter(Mandatory = $true)]
    [System.String]$resourceGroupName,
    [Parameter(Mandatory = $true)]
    [String]$appServicePlanName 
)
{

    Write-Host "SafeCreateAppServicePlan.Parameter:location: $location"
    Write-Host "SafeCreateAppServicePlan.Parameter:resourceGroupName: $resourceGroupName"
    Write-Host "SafeCreateAppServicePlan.Parameter:appServicePlanName: $appServicePlanName"

    $SkuName = "Y1"
    $SkuTier = "Dynamic"
    $WebAppApiVersion = "2015-08-01"

    $fullObject = @{
        location = $location
        sku = @{
            name = $SkuName
            tier = $SkuTier
        }
    }

    Write-Host "Ensuring the $appServicePlanName app service plan exists"
    $plan = Get-AzureRmAppServicePlan -Name $appServicePlanName -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue
    if(-not $plan) {
        Write-Host "Creating $appServicePlanName app service plan"
        New-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/serverfarms -Name $appServicePlanName -IsFullObject -PropertyObject $fullObject -ApiVersion $WebAppApiVersion -Force
    }
    else {
        Write-Host "$appServicePlanName app service plan already exists"   
    }

}

我得到的帮助:

https://github.com/davidebbo/AzureWebsitesSamples/blob/master/PowerShell/HelperFunctions.ps1

(在上面的网址中搜索“SkuName”以找到魔术线。

请注意,这只是为 azure 函数部署基础设施的整体方程式的一部分(如果您不使用arm 模板)。当我说基础设施时,下面的代码本身不会部署 azure-functions,但下面的代码将设置执行此操作所需的基础设施。

这位朋友解释得很好:

https://clouddeveloper.space/2017/10/26/deploy-azure-function-using-powershell/

“clouddeveloper”基本上说,对于消费计划天蓝色功能,您需要有一个存储帐户。这与通过天蓝色门户手动添加功能应用程序时获得的“信息”按钮一致。

“支持 Blob、队列和表存储的存储帐户是 必需的。当使用消耗计划函数定义时 存储在文件存储中。”

enter image description here

因此,我的完整代码将创建一个应用程序服务计划、创建一个存储帐户、创建一个应用程序服务(即 azure 函数/函数应用程序友好)并将存储帐户与应用程序服务相匹配:

function SafeCreateAppServicePlan(
    [Parameter(Mandatory = $true)]
    [System.String]$location, 
    [Parameter(Mandatory = $true)]
    [System.String]$resourceGroupName,
    [Parameter(Mandatory = $true)]
    [String]$appServicePlanName 
)
{

    Write-Host "SafeCreateAppServicePlan.Parameter:location: $location"
    Write-Host "SafeCreateAppServicePlan.Parameter:resourceGroupName: $resourceGroupName"
    Write-Host "SafeCreateAppServicePlan.Parameter:appServicePlanName: $appServicePlanName"

    $SkuName = "Y1"
    $SkuTier = "Dynamic"
    $WebAppApiVersion = "2015-08-01"

    $fullObject = @{
        location = $location
        sku = @{
            name = $SkuName
            tier = $SkuTier
        }
    }

    Write-Host "Ensuring the $appServicePlanName app service plan exists"
    $plan = Get-AzureRmAppServicePlan -Name $appServicePlanName -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue
    if(-not $plan) {
        Write-Host "Creating $appServicePlanName app service plan"
        New-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/serverfarms -Name $appServicePlanName -IsFullObject -PropertyObject $fullObject -ApiVersion $WebAppApiVersion -Force
    }
    else {
        Write-Host "$appServicePlanName app service plan already exists"   
    }

}

function SafeCreateAzureFunctionAppService(
    [Parameter(Mandatory = $true)]
    [System.String]$location, 
    [Parameter(Mandatory = $true)]
    [System.String]$resourceGroupName,
    [Parameter(Mandatory = $true)]
    [String]$appServicePlanName,
    [Parameter(Mandatory = $true)]
    [String]$functionAppName        
)
{

    Write-Host "SafeCreateAzureFunctionAppService.Parameter:location: $location"
    Write-Host "SafeCreateAzureFunctionAppService.Parameter:resourceGroupName: $resourceGroupName"
    Write-Host "SafeCreateAzureFunctionAppService.Parameter:appServicePlanName: $appServicePlanName"
    Write-Host "SafeCreateAzureFunctionAppService.Parameter:functionAppName: $functionAppName"

    [String]$planId = ''

    $plan = Get-AzureRmAppServicePlan -Name $appServicePlanName -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue
    if(-not $plan) {
        throw [System.ArgumentOutOfRangeException] "Missing App Service Plan.  (ResourceGroupName='$resourceGroupName', AppServicePlan.Name = '$appServicePlanName')"
    }
    else {
        Write-Host "START AzureRmAppServicePlan Properties"   
        $plan.PSObject.Properties   
        Write-Host "END AzureRmAppServicePlan Properties"   

        #get the planId, so that can be used as the backing-app-service-plan for this AppService
        [String]$planId = $plan.Id
    }

    #wire up the necessary properties for this AppService
    $props = @{
        ServerFarmId = $planId
        }


    $functionAppResource = Get-AzureRmResource | Where-Object { $_.ResourceName -eq $functionAppName -And $_.ResourceType -eq 'Microsoft.Web/Sites' }

    if ($functionAppResource -eq $null)
    {
        New-AzureRmResource -ResourceType 'Microsoft.Web/Sites' -ResourceName $functionAppName -kind 'functionapp' -Location $location -ResourceGroupName $resourceGroupName -Properties $props -force
    }    

}


function SafeCreateStorageAccountToBackConsumptionAzureFunctions(
    [Parameter(Mandatory = $true)]
    [System.String]$location, 
    [Parameter(Mandatory = $true)]
    [System.String]$resourceGroupName,
    [Parameter(Mandatory = $true)]
    [String]$storageAccountName   
)
{

    Write-Host "SafeCreateStorageAccount.Parameter:location: $location"
    Write-Host "SafeCreateStorageAccount.Parameter:resourceGroupName: $resourceGroupName"
    Write-Host "SafeCreateStorageAccount.Parameter:storageAccountName: $storageAccountName"

    $azureRmStorageAccountGetCheck = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName -ErrorAction SilentlyContinue

    if(-not $azureRmStorageAccountGetCheck) 
    {
        New-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -AccountName $storageAccountName -Location $location -SkuName 'Standard_LRS'
    }
    else 
    {
        Write-Host "$storageAccountName storage account already exists"
    }    
}



function MatchStorageSettingsToAppService(
    [Parameter(Mandatory = $true)]
    [System.String]$location, 
    [Parameter(Mandatory = $true)]
    [System.String]$resourceGroupName,
    [Parameter(Mandatory = $true)]
    [String]$functionAppName,
    [Parameter(Mandatory = $true)]
    [String]$storageAccountName       
)
{

    Write-Host "MatchStorageSettingsToAppService.Parameter:location: $location"
    Write-Host "MatchStorageSettingsToAppService.Parameter:resourceGroupName: $resourceGroupName"
    Write-Host "MatchStorageSettingsToAppService.Parameter:functionAppName: $functionAppName"    
    Write-Host "MatchStorageSettingsToAppService.Parameter:storageAccountName: $storageAccountName"

    $keys = Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -AccountName $storageAccountName

    $accountKey = $keys | Where-Object { $_.KeyName -eq "Key1" } | Select Value

    $storageAccountConnectionString = 'DefaultEndpointsProtocol=https;AccountName=' + $storageAccountName + ';AccountKey=' + $accountKey.Value

    $AppSettings = @{}

    $AppSettings = @{'AzureWebJobsDashboard' = $storageAccountConnectionString;

    'AzureWebJobsStorage' = $storageAccountConnectionString;

    'FUNCTIONS_EXTENSION_VERSION' = '~1';

    'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' = $storageAccountConnectionString;

    'WEBSITE_CONTENTSHARE' = $storageAccountName;

}

    Set-AzureRMWebApp -Name $functionAppName -ResourceGroupName $resourceGroupName -AppSettings $AppSettings

}

我也从这个 ARM 模板中得到了一些提示:

https://github.com/Azure/azure-quickstart-templates/blob/master/101-function-app-create-dynamic/azuredeploy.json

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Powershell 创建基于消耗的应用服务计划 的相关文章

随机推荐

  • 将动态数组包装到 STL/Boost 容器中?

    我需要将动态分配的数组 例如从 a new double 100 包装到 std vector 最好 而不复制数组 此限制是由于我想要包装的数组是从文件映射而来的 因此仅执行向量 a a size 就会使内存使用量增加一倍 有什么技巧可以做
  • 将“大”表拆分为较小的表

    我想将一个 大 表 很多列 拆分为较小的表 例如每两列 有没有简单的方法可以做到这一点 我这里只有桌子http jsfiddle net xy3UF 4 例如 我想将其分成每两列 结果我应该有一个三个表 其中包含 列 每列包含大表中的 2
  • 访问文件中的单个字符效率低下? (C++)

    我一直认为在处理文本文件时 首先将内容 或部分内容 读入 std string 或 char 数组会更有效 因为根据我有限的理解 文件是从内存中读取的块比单个字符的大小大得多 然而 我听说现代操作系统通常实际上并不直接从文件中读取 这使得我
  • Jqgrid 标题位于两行或更多行

    我有以下问题 我需要放置 Jqgrid 的两行或更多行标题内容 我看到了扎克提供的例子jqgrid双标题在替代方案下 但通过仅更改 css 我在网格上没有得到任何更改 是否可以有一个更完整的示例来重现该行为 谢谢 安吉洛 如果我理解正确 您
  • ImportError:无法导入名称namedtuple

    我有一个 python 脚本 运行时会产生以下错误 import urllib2 File C Python27 lib urllib2 py line 94 in
  • 在 iPad 应用程序中包含同一系列的多种字体 [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 当我必须包含同一字体系列的多种字体时 我在 iPad
  • 打开 JSF Facelets 页面会显示“此 XML 文件似乎没有任何与之关联的样式信息”。

    我正在尝试在其他计算机上的 Apache Tomcat 上运行我的 Eclipse JSF 项目 我创建了一个 WAR 文件本教程 但是 当我部署 WAR 并在 Firefox 中打开 Facelet 页面时 我仅收到以下错误消息 该 XM
  • 如何在 Android WebView 中启用地址栏?

    实际上 我在我的应用程序中使用了 WebView 而且效果非常好 现在我希望能够更改实际的 URL 就像 Android Stock 浏览器中的地址栏一样 您可以在其中看到 URL 并且可以轻松更改它 我怎样才能启用这个栏 还是我必须自己实
  • 如何在 Mac OS X 中跟踪程序的系统调用?

    我想跟踪系统调用find命令调试一些性能问题但是我不知道如何在 Mac OS X Yosemite 上执行此操作 如何跟踪任意程序的系统调用 类似于strace在 FreeBSD 上有吗 我对跟踪文件系统相关的调用特别感兴趣 建议接受的答案
  • Bash globbing - 在一些特定情况下自动扩展?

    我明白通配符 单独 将以这样的方式展开 即 当前文件夹中的所有非隐藏文件 其中隐藏文件是以句点为前缀的文件 我认为有两个用例有用 但我不知道如何正确执行 你怎么能通配 当前文件夹中的所有文件 包括隐藏文件 但不包括 or 你如何才能找到 当
  • 如何在android中的表格布局中给出单元格的边框

    我有一个问题 如何以编程方式在 Android 的表格布局中提供单元格边框 这是我的代码 TableLayout table TableLayout findViewById R id linear Layout List TableRow
  • htaccess:在 RewriteCond 中排除某些域

    这是我的 htaccess 代码 因此 如果用户仅输入domain com 则会被重定向到www domain com RewriteBase RewriteCond HTTP HOST www domain com NC RewriteR
  • AVCaptureMetadataOutput setMetadataObjectTypes 发现不支持的类型

    我知道有人问过这个问题 但很抱歉我没有找到答案 dispatchQueue dispatch queue create myQueue NULL captureMetadaOutput setMetadataObjectsDelegate
  • 使用 Jquery 将变量通过 POST 传递到另一个页面

    我对 Jquery 比较陌生 我想知道如何将变量发布到另一个页面然后重定向 我使用了 ajax 函数 重定向工作正常 但 POST 中没有捕获任何变量 它们是空的 function linkWO ajax type POST content
  • 从桌面应用程序使用 Windows 8 Toast 通知

    我开发了一个桌面应用程序 它是一个简单的 Windows exe 文件 它在 Windows 8 上运行良好 我现在尝试使用 toast notification 来向用户显示一些警报 因此 我使用 Microsoft 示例进行了培训 可在
  • 使用 Mirth Connect 将 XML 转换为 HL7 消息

    我正在使用 Mirth Connect v2 0 但陷入了一项任务 将 XML 转换为 HL7 v3 我已连接到 Ms Access 数据库 医院系统位于 Access 中 我已设置通道并将目标选项卡中的连接器类型设置为文件写入器 当我部署
  • Spring MVC Rest 服务 - 线程数(控制器实例)

    在我们的应用程序中 我们希望实现更高的吞吐量 因此我只想知道线程在 Spring MVC 控制器中如何工作 在此先感谢您的帮助 这对我有帮助 http community jaspersoft com wiki how increase m
  • 如何将管道分隔的文本文件数据导入到 SQL Server 表

    我有以以下模式表示为文本文件的数据库表 0 ALGERIA 0 haggle carefully f 1 ARGENTINA 1 al foxes promise 2 BRAZIL 1 y alongside of the pendal 3
  • C++ 和 C# 中的静态变量有什么区别?

    静态变量在 C 中的功能与在 C 中的功能相同或相似吗 Edit 使用 C 您可以在许多不同的上下文中使用静态变量 例如 1 全局变量 2 局部函数变量 3 类成员 C 中的类似用法与 C 的行为是否相似 静态在 C 中具有多种含义 C 中
  • 使用 Powershell 创建基于消耗的应用服务计划

    我找到了这个答案question 有谁知道如何创建一个消耗Azure 的应用程序服务计划 当我查看属性时 使用https resources azure com 我 由 Gui 制作的一个 我看到以下属性 sku name Y1 tier