powershell - 为什么我的 powershell 上传到 lambda 将目录视为文件?
问题描述
使用以下脚本
$tmpdir = New-TemporaryFile | %{ rm $_; mkdir $_ }
$tempFile = New-TemporaryFile
$ziplocation = $tempFile.FullName + ".zip"
$ziplocation
$filepath = Get-ChildItem $file
$filename = $filepath.Name
$fileWithoutExtension = $filepath.BaseName
$directory = Split-Path -path $file -parent
$sharedFolder = Join-Path -Path $directory -ChildPath "/shared"
$sharedFolder
$lambdaName = "$($enviroment)__$($fileWithoutExtension)"
$s3path = "$($enviroment)/$($lambdaName).zip"
$s3fullPath = "s3://firmware-repo-source-code/$($enviroment)/$($lambdaName).zip"
Copy-Item -Path $file -Destination $tmpdir
"Base file copied"
Rename-Item -path(Join-Path -Path $tmpdir -ChildPath $filename) -NewName "index.js"
Copy-Item -Path $sharedFolder -Destination $tmpdir -Recurse -Container
"shared files copied"
#Compress-Archive -Path $tmpdir -DestinationPath $ziplocation
Compress-Archive -Path ($tmpdir.FullName + "\*") -DestinationPath $ziplocation
"zip created"
aws lambda update-function-code --function-name $lambdaName --zip-file ("fileb://" + $ziplocation)
"Lambda updated"
function New-TemporaryDirectory {
$parent = [System.IO.Path]::GetTempPath()
[string] $name = [System.Guid]::NewGuid()
New-Item -ItemType Directory -Path (Join-Path $parent $name)
}
我在 Windows 机器上运行 powershell 版本 5.1.17763.316。我可以以编程方式将 zip 上传到 s3 并在文件资源管理器中查看,但如果我通过 console.aws.com 上传相同的 zip,我也会遇到同样的问题。
解决方案
ZIP 标准使用 / 作为路径分隔符,但 Powershell 中的 Compress-Archive 使用 \,所以当它被 Lambda 解压缩时,它认为它们是长文件名而不是分隔路径。
推荐阅读
- r - 每次通过 for 循环时将向量添加到数据帧
- r - 使用 NSE 构造公式
- python - 如果我添加滚动条,所有标签都会消失
- javascript - 以 WMS 为源的 OpenLayer 6.3.1 中的 MarkerClusters
- python-3.x - 当 itersize 小于数据大小且 fetch number 小于 itersize 时,psycopg2 服务器端游标如何操作?
- python - AttributeError: 'str' object has no attribute 'P' 当尝试从所有 .odt 文件中递归提取文本时,使用 odfpy 库
- flutter - 在 Flutter 中绘制圆形菜单
- java - 带有蓝色事物的 VS Code Java 输出“HelloWorld”
- android - 检查下载中的自定义文件夹中是否存在文件 - 不推荐使用 getExternalStoragePublicDirectory
- c# - 在 Parallel.ForEach 循环 C# 中错误捕获的特定异常