azure - 如何使用powershell从远程zip文件部署functionapp
问题描述
我想使用 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:找不到驱动器。名为“https”的驱动器不存在。
如何从远程 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
先决条件
需要提供SAS(共享访问签名)URI而不是资源 URL,其中包括 SAS 令牌以执行经过身份验证的 请求
选项 2
$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
推荐阅读
- javascript - 简单而愚蠢的onmouseout前夕
- php - 多字段表单到sql方法post请求
- node.js - 为什么我得到 E11000 节点 js mongoose
- c# - Windows Defender 检测到我作为病毒制作的无害 c# 程序
- sql-server - DbccFilesCompact 被阻止
- c# - 如何从里面有两个列表的类中获取数据?
- python - 我怎么转。进入 ._ 这个命令?
- linux - hdfs:找不到命令
- java - 发生意外错误 org.apache.jasper.runtime.JspRuntimeLibrary.releaseTag
- php - Laravel 5.6 查询生成器嵌套子查询