iOS AWS v2 S3传输管理器必须使用指定的端点 [英] iOS AWS v2 S3 Transfer Manager must use specified endpoint
问题描述
我正在开发一个使用AWS作为后端的iOS应用程序。由于我希望用户能够在全球范围内使用,因此我需要切换应用下载照片的位置,以提高延迟性能。我在EUWest1中创建了一个S3存储桶,在APNorthEast1中创建了另一个存储桶。 Yosuke在这里说( https://forums.aws.amazon.com/ message.jspa?messageID = 586581#586581 ),您可以将AWSServiceManager.defaultServiceManager()的默认配置从一个区域更改为另一个区域,以防止出错。
I am developing an iOS app using AWS as its backend. Since I expect users to be world wide, I need to switch where the app should download photos in order to increase latency performance. I have created a S3 bucket in EUWest1 and the other in APNorthEast1. As Yosuke said here (https://forums.aws.amazon.com/message.jspa?messageID=586581#586581), you can change the default configuration of AWSServiceManager.defaultServiceManager() from one region to another in order to prevent the error.
但是,即使我按照他的提示,我仍然有相同的错误结果。错误是:
But, I still have the same error result even if I followed his tip. Error is:
错误域= com.amazonaws.AWSS3ErrorDomain代码= 0操作无法完成。(com.amazonaws。 AWSS3ErrorDomain错误0.)UserInfo = 0x14fb7720 {RequestId = D708XXX8E1EDBXXX,Endpoint = bucket-ap-northeast-1.s3-ap-northeast-1.amazonaws.com,Message =您尝试访问的存储区必须使用指定的端点。请将以后的所有请求发送到此端点。,HostId = xxxY31S3yFhpssQe1EsfipWWLw =,Code = PermanentRedirect,Bucket = bucket-ap-northeast-1}
Error Domain=com.amazonaws.AWSS3ErrorDomain Code=0 "The operation couldn’t be completed. (com.amazonaws.AWSS3ErrorDomain error 0.)" UserInfo=0x14fb7720 {RequestId=D708XXX8E1EDBXXX, Endpoint=bucket-ap-northeast-1.s3-ap-northeast-1.amazonaws.com, Message=The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint., HostId=xxxY31S3yFhpssQe1EsfipWWLw=, Code=PermanentRedirect, Bucket=bucket-ap-northeast-1}
这是我的代码:
var credentialsProvider = AWSCognitoCredentialsProvider.credentialsWithRegionType(kCognitoRegionType, accountId: kAWSAccountID, identityPoolId: kCognitoPoolID, unauthRoleArn: kCognitoRoleUnauth, authRoleArn: kCognitoRoleAuth)
var serviceConfiguration = AWSServiceConfiguration(region: AWSRegionType.APNortheast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().setDefaultServiceConfiguration(serviceConfiguration)
var transferManager = AWSS3TransferManager.defaultS3TransferManager()
transferManager.download(downloadRequest)
欢迎任何建议!谢谢!
推荐答案
AWS v2的答案
虽然看起来像如果您通过使用代码中的区域正确设置 AWSServiceConfiguration
,那么您仍然使用默认的 AWSS3TransferManager
( var transferManager = AWSS3TransferManager.defaultS3TransferManager()
)。而是使用 docs 将传输管理器的配置设置为您已经创建的 serviceConfiguration
。
Although it seems as if you properly set the AWSServiceConfiguration
by using the region in your code, you're still using the default AWSS3TransferManager
(var transferManager = AWSS3TransferManager.defaultS3TransferManager()
). Instead, use the custom init specified in the docs to set that transfer manager's configuration to the serviceConfiguration
you've already created.
AWS v1的答案
如果您创建的EUWest1和APNorthEast1等非美国标准的存储桶,则不能使用典型的路径样式语法( http://s3.amazonaws.com 或不需要指定的端点)来访问桶。
If you create a bucket like EUWest1 and APNorthEast1 that is not US Standard, you cannot use typical path-style syntax ("http://s3.amazonaws.com" or no specified endpoint required) to access the bucket.
假设 downloadRequest
是一个 S3GetObjectRequest
,之前执行transferManager的下载时,您应该设置 S3GetObjectRequest
的端点以匹配存储区域。
Assuming downloadRequest
is an S3GetObjectRequest
, before performing the transferManager's download, you should set the endpoint of the S3GetObjectRequest
to match the bucket region.
对于EUWest1,您可以将端点设置为:
For EUWest1, you can set the endpoint to:
[downloadRequest setEndpoint:@"s3-eu-west-1.amazonaws.com.com"];
对于APNorthEast1,您可以将端点设置为:
For APNorthEast1, you can set the endpoint to:
[downloadRequest setEndpoint:@"s3-ap-northeast-1.amazonaws.com"];
可以使用整个端点列表这里
The entire list of endpoints is available here
这篇关于iOS AWS v2 S3传输管理器必须使用指定的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!