amazon-web-services - 如何使用 Powershell 访问 Transfer Accelerated S3 存储桶
问题描述
我有一个在访问普通 S3 存储桶时有效的 powershell 脚本,但是如果我将存储桶名称更改为 Transfer Accelerated 存储桶名称,则会出现错误“找不到存储桶”。
包括使用注释掉的无效存储桶名称的脚本。
# 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 端点。
推荐阅读
- perl - 需要在perl的foreach循环中查找字符串中的重复值
- r - 从数据框创建虚拟变量
- javascript - 设置当前当地时间的最简单方法是什么
- java - Java Program Won't Stop Accepting User Input
- laravel - 更改 Nova 资源的资源 url
- android - Retrofit 2 Close ErrorResponse Body
- python - statement based on whether string field starts with number
- javascript - 从 Microsoft Graph API 请求列表项时接收空数组
- python - SQLAlchemy 不能用主键反映表
- javascript - 为什么浮点误差会根据小数的位置而变化?