gpt4 book ai didi

azure - 如何使用 powershell 从远程 zip 文件部署函数应用程序

转载 作者:行者123 更新时间:2023-12-03 02:49:25 25 4
gpt4 key购买 nike

我想使用 zip 文件在 azure 中部署一个 functionApp,该文件位于使用 powershell 的另一个 azure blob 存储中。我尝试了以下方法

#PowerShell
$username = "<deployment_user>"
$password = "<deployment_password>"
$filePath = "https://xxxxx.blob.core.windows.net/container/zzzz.zip"
$apiUrl = "https://<app_name>.scm.azurewebsites.net/api/zipdeploy"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f
$username, $password)))
$userAgent = "powershell/1.0"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath - ContentType "multipart/form-data"

但我收到以下错误消息,例如

Invoke-RestMethod : Cannot find drive. A drive with the name 'https' does not exist.

如何从远程 URL 文件进行部署?

最佳答案

由于 Invoke-RestMethod InFile 接受文件中的内容,因此需要首先显式下载 blob 内容。

选项 1

$fileUrl = "https://xxxxx.blob.core.windows.net/container/zzzz.zip"
$token = 'sp=r&st=2019-07-06T21:41:45Z&se=2019-07-07T05:41:45Z&spr=https&sv=2018-03-28&sig=9ud%2FiJ6GBccxZfyrKsZtP69lwuralu1D0QiiESa%2FXgo%3D&sr=b'
$filePath = [System.IO.Path]::GetFileName($fileUrl)
Invoke-WebRequest ('{0}?{1}' -f $fileUrl, $token) -OutFile $filePath

Prerequisite

Instead of resource Url, SAS (Shared Access Signature) URI needs to be provided which includes a SAS token to perform the authenticated request

选项 2

通过 Azure Storage Cmdlets :

$StorageAccountName = 'yourstorageaccount'
$StorageAccountKey = Get-AzureStorageKey -StorageAccountName $StorageAccountName
$StorageContext = New-AzureStorageContext $StorageAccountName -StorageAccountKey $StorageAccountKey.Primary
$FileName = 'zzzz.zip'
$OutputPath = 'C:\Temp'
$ContainerName = 'yourcontainer'
Get-AzureStorageBlobContent -Blob $FilebName -Container $ContainerName -Destination $OutputPath -Context $StorageContext

关于azure - 如何使用 powershell 从远程 zip 文件部署函数应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56915330/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com