繁体   English   中英

如何使用Powershell访问Transfer Accelerated S3存储桶

[英]How to access Transfer Accelerated S3 bucket using Powershell

我有一个PowerShell脚本,在访问普通S3存储桶时有效,但是如果我将存储桶名称更改为传输加速存储桶名称,则会出现错误“存储桶未找到”。

包括使用注释掉的桶名不起作用的脚本。

# 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
   }
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM