amazon-web-services - 如何使用 Powershell 访问 Transfer Accelerated S3 存储桶

标签 amazon-web-services powershell amazon-s3

我有一个 powershell 脚本可以在访问普通 S3 存储桶时使用,但如果我将存储桶名称更改为 Transfer Accelerated 存储桶名称,则会出现错误“未找到存储桶”。

包括与不起作用的注释掉的 bucketname 一起工作的脚本。

# Your account access key - must have read access to your S3 Bucket
$accessKey = "KEY"
# Your account secret access key
$secretKey = "SECRETKEY"
# 
$region = "us-east-1"
# The name of your S3 Bucket
$bucket = "myBucket"
#The above works!! - but if i comment out the above and uncomment 
the below line then it no longer works.
#$bucket = "myBucket.s3-accelerate.amazonaws.com"

# The folder in your bucket to copy, including trailing slash. Leave 
blank to copy the entire bucket
$keyPrefix = "myFolder/"
# The local file path where files should be copied
$localPath = "D:\S3_Files\myFolder\"

$objects = Get-S3Object -BucketName $bucket -KeyPrefix $keyPrefix - 
AccessKey $accessKey -SecretKey $secretKey -Region $region

foreach($object in $objects) {
    $localFileName = $object.Key -replace $keyPrefix, ''
    if ($localFileName -ne '') {
        $localFilePath = Join-Path $localPath $localFileName
        Copy-S3Object -BucketName $bucket -Key $object.Key -LocalFile $localFilePath -AccessKey $accessKey -SecretKey $secretKey -Region $region
   }
}

最佳答案

无需为您的存储桶指定 s3-accelerate 名称,只需使用常规存储桶名称并将 -UseAccelerateEndpoint 开关添加到您的 S3 命令即可。然后,cmdlet 将为您定位加速的 S3 端点。

关于amazon-web-services - 如何使用 Powershell 访问 Transfer Accelerated S3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54412997/

相关文章:

amazon-web-services - AWS 云形成 : Failed to run cfn-init

powershell - 在powershell中执行表达式的结果

amazon-web-services - aws cli 假设角色有效,但在 s3 上仍然被拒绝许可

ruby - aws/s3 gem 与 JRuby 不兼容

linux - 多平台 Amazon-AWS 开发

javascript - AWS Lambda 如何读取查询参数

powershell - 运行powershell时 "- <"是什么意思?

powershell - 使用 Powershell 脚本不以表格形式显示文件数据

amazon-web-services - 如果 lambda 代码上传到 S3,如何更新 lambda 函数代码

amazon-web-services - AWS AutoScaling是否有可能在计费小时边界内永不终止实例?