powershell - 我可以使用 powershell 在一个命令中复制 s3 中的 "folder"吗?

标签 powershell amazon-web-services amazon-s3

我有一个带有 stageproduction 前缀的 s3 存储桶。 QA 之后,我想将所有对象从阶段复制到生产中。我正在尝试了解如何使用一个命令执行此操作。

我的谷歌搜索仅显示以下内容,用于复制单个对象:

http://docs.aws.amazon.com/powershell/latest/reference/items/Copy-S3Object.html

我可以通过以下方式一次上传一个文件夹

Write-S3Object -BucketName $bucketName -Folder $myfolder -Keyprefix $Keyprefix

但是 Copy-S3Object 命令似乎不接受前缀和目标前缀,例如。

执行此操作的最佳方法是什么?

最佳答案

好的,看起来 AWS CLI 在很多情况下都是一个很好的解决方案,但实际上我在这里只能使用 Powershell。

这是我的解决方案:

$objects = Get-S3Object -BucketName $bucketName -KeyPrefix $stageKeyPrefix

foreach($object in $objects) {
    $prodKey = $object.Key -replace $stageKeyPrefix, $prodKeyPrefix
    Copy-S3Object -BucketName $bucket -Key $object.Key -DestinationKey $prodKey
}

关于powershell - 我可以使用 powershell 在一个命令中复制 s3 中的 "folder"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47832586/

相关文章:

security - 哈希表漏洞(属性覆盖)?

java - AWS 的 AsyncClients in Java 线程安全且持久吗?

amazon-web-services - 如何从 AWS CloudWatch 应用程序 ELB 获取延迟指标?

ios - Amazon AWS S3 从 iOS 设备上传

Powershell:Foreach 不工作?

powershell - 用于配置 IIS 应用程序池的 DSC

powershell - 如何从.ps1文件运行powershell脚本?

python - EC2 自动缩放 Python 脚本

security - 关于 AWS S3 SSL 弃用和 iOS SDK 的可疑之处

python - 在 Elastic Beanstalk Postgresql 中创建 Django super 用户