1

我试图弄清楚为什么在 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 : 指定的存储桶不存在

这些细节可能很重要

  • 对于它的价值,我们的存储桶名称都是大写字母。(“公司客户”)
  • 这实际上在一小时左右前在我的机器上工作。然后我想并行做一些事情,所以我下载了 powershell v4 和最新的 AWS 工具。这个问题一直在发生。我已经恢复到powershell 3,但问题仍然存在。
  • 我一直无法找到旧版本的 amazon 1.x 工具来测试

到目前为止的故障排除

  • 如果我只执行Get-S3Bucket OURBUCKETNAME,它可以工作
  • 如果我执行脚本,不使用管道Copy-S3Object命令,它就会工作,输出我在文件中导入的所有对象。
  • 我检查了一下,根据智能感知,Copy- 命令上似乎没有BucketName参数。S3Object如果我尝试指定一个,我会收到错误消息。
4

1 回答 1

2

似乎还有一个名为的 cmdletRead-S3Object最终得到相同的结果。不得不用那个。

没有看到任何关于Copy-S3object被弃用或更改其功能的信息,所以这很不幸。

假设你有:

  • 电源外壳 V3
  • 适用于 Powershell v2.x 的亚马逊工具
  • 适当的 Amazon 凭证

然后下面的脚本应该工作:

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 工作流中,更好地处理凭据等),但这可以以最基本的形式完成。

于 2013-12-20T00:54:35.157 回答