我试图弄清楚为什么在AWS工具1.x中运行的脚本(我认为1.1.16?)在升级到最新的AWS工具(2.0.3)后现在无法正常工作
Import-Module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
$creds = New-AWSCredentials -AccessKey [REDACTED] -SecretKey [REDACTED]
Set-AWSCredentials -Credentials $creds
$a = Get-Content C:\users\killeens\desktop\temp\AmazonKeysToDownload.txt
$startingpath = "G:\TheFiles\"
$a | ForEach-Object {
$keyname = $_
$fullpath = $startingpath + $keyname
write-host "fullpath: "$fullpath
Get-S3Bucket -BucketName OURBUCKETNAME | Get-S3Object -Key $_ | Copy-S3Object -Key $keyname -LocalFile $fullpath
}
在1.1.16中,这很好。
现在,在2.0.3的截止日期之前,我收到以下错误:
Copy-S3Object:指定的存储桶不存在
Get-S3Bucket OURBUCKETNAME
,则可以Copy-S3Object
命令,它就会工作,输出我在文件中导入的所有对象。BucketName
命令似乎没有S3Object
参数。如果我尝试指定一个,我会收到错误。答案 0 :(得分:2)
似乎还有一个名为Read-S3Object
的cmdlet,其结果相同。不得不使用它。
没有看到关于Copy-S3object
被弃用或更改其功能的任何内容,所以这很不幸。
假设你有:
然后以下脚本应该可以工作:
Import-Module "C:\Program Files (x86)\AWS Tools\PowerShell\AWSPowerShell\AWSPowerShell.psd1"
### SET ONLY THE VARIABLES BELOW ###
$accessKey = "" # Amazon access key.
$secretKey = "" # Amazon secret key.
$fileContainingAmazonKeysSeparatedByNewLine = "" # Full path to a file, e.g. "C:\users\killeens\desktop\myfile.txt"
$existingFolderToPlaceDownloadedFilesIn = "" # Path to a folder, including a trailing slash, such as "C:\MyDownloadedFiles\" NOTE: This folder must already exist.
$amazonBucketName = "" # the name of the Amazon bucket you'll be retrieving the keys for.
### SET ONLY THE VARIABLES ABOVE ###
$creds = New-AWSCredentials -AccessKey $accessKey -SecretKey $secretKey
Set-AWSCredentials -Credentials $creds
$amazonKeysToDownload = Get-Content $fileContainingAmazonKeysSeparatedByNewLine
$uniqueAmazonKeys = $amazonKeysToDownload | Sort-Object | Get-Unique
$startingpath = $existingFolderToPlaceDownloadedFilesIn
$uniqueAmazonKeys | ForEach-Object {
$keyname = $_
$fullpath = $startingpath + $keyname
Read-S3Object -BucketName $amazonBucketName -Key $keyname -File $fullpath
}
显然会有更好的方法来产生这个(作为一个接受参数的函数,在具有并行循环和节流计数的Powershell v4工作流程中,更好地处理凭证等)但这可以在最基本的情况下完成形式。