Jef*_*tin 8 powershell amazon-web-services aws-powershell aws-lambda
我一直在尝试使用AWS Update-LMFunctionCode将我的文件部署到AWS中的现有lambda函数.
与Publish-LMFunction不同,我只能提供zipFile(-FunctionZip)的路径,Update-LMFunction需要一个用于其-Zipfile参数的内存流.
有一个例子将本地zipfile从磁盘加载到一个有效的内存流?我的初始调用是收到文件无法解压缩的错误...
$deployedFn = Get-LMFunction -FunctionName $functionname
"Function Exists - trying to update"
try{
[system.io.stream]$zipStream = [system.io.File]::OpenRead($zipFile)
[byte[]]$filebytes = New-Object byte[] $zipStream.length
[void] $zipStream.Read($filebytes, 0, $zipStream.Length)
$zipStream.Close()
"$($filebytes.length)"
$zipString = [System.Convert]::ToBase64String($filebytes)
$ms = new-Object IO.MemoryStream
$sw = new-Object IO.StreamWriter $ms
$sw.Write($zipString)
Update-LMFunctionCode -FunctionName $functionname -ZipFile $ms
}
catch{
$ErrorMessage = $_.Exception.Message
Write-Host $ErrorMessage
break
}
Run Code Online (Sandbox Code Playgroud)
Powershell函数的文档在这里:http://docs.aws.amazon.com/powershell/latest/reference/items/Update-LMFunctionCode.html虽然它想要生活在一个框架中......
Jam*_*mes 10
尝试使用该CopyTo方法从一个流复制到另一个流:
try {
$zipFilePath = "index.zip"
$zipFileItem = Get-Item -Path $zipFilePath
$fileStream = $zipFileItem.OpenRead()
$memoryStream = New-Object System.IO.MemoryStream
$fileStream.CopyTo($memoryStream)
Update-LMFunctionCode -FunctionName "PSDeployed" -ZipFile $memoryStream
}
finally {
$fileStream.Close()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3570 次 |
| 最近记录: |