简体   繁体   English

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

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

I have a powershell script that works when accessing a normal S3 bucket but if i change the bucket name to the Transfer Accelerated bucket name then it gives an error "Bucket not found". 我有一个PowerShell脚本,在访问普通S3存储桶时有效,但是如果我将存储桶名称更改为传输加速存储桶名称,则会出现错误“存储桶未找到”。

Including the script that works with a commented out bucketname that doesn't work. 包括使用注释掉的桶名不起作用的脚本。

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

Instead of specifying the s3-accelerate name for your bucket, just use the regular bucket name and add the -UseAccelerateEndpoint switch to your S3 commands. 您只需使用常规存储桶名称并将-UseAccelerateEndpoint开关添加到S3命令,而不是为存储桶指定s3-accelerate名称。 The cmdlets will then target the accelerated S3 endpoints for you. 然后,cmdlet将为您定位加速的S3端点。

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

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