[英]AWS S3: confusion on bucket region and identityPoolId (Swift)
I'm having trouble downloading a file from my AWS S3 bucket (Swift/iOS app). 我无法从AWS S3存储桶(Swift / iOS应用)下载文件。 It seems to be one of two problems, but I can't tell which:
这似乎是两个问题之一,但我无法确定是哪一个:
If I create the credentialsProvider like this: 如果我这样创建凭据提供者:
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"us-west-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"];
I get the following error: 我收到以下错误:
[Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=Identity 'us-west-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' not found.}]
I noticed the mismatch on the line where I create the credentials provider: the regionType is AWSRegionUSEast1, but I have "us-west-2" as part of the identityPoolId. 我在创建凭证提供程序的那一行上注意到不匹配:regionType是AWSRegionUSEast1,但是我将“ us-west-2”作为identityPoolId的一部分。
If I change the regionType to AWSRegionUSWest2 (to match my id), the ResourceNotFoundExeception goes away. 如果我将regionType更改为AWSRegionUSWest2(以匹配我的ID),则ResourceNotFoundExeception将消失。 But then I get this:
但是然后我得到这个:
<Error><Code>PermanentRedirect</Code><Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message><Bucket>sportsmanregs</Bucket><Endpoint>s3.amazonaws.com</Endpoint><RequestId>AEFD833FF4E7B6F1</RequestId><HostId>mYxbBKlzTeWgVZW4W060+ESiBhWuxmfDDFE6UriXG7bqxA5NWuRbH9lu4NuGCaU/7H8f1hjAukA=</HostId></Error>
What is interesting is the above error is found in the data object in the completion handler, as in "data" in the following: 有趣的是,上述错误是在完成处理程序的数据对象中找到的,如以下“数据”中所示:
completionHandler = {
(task, location, data, error) -> Void in DispatchQueue.main.async( execute: {
So the completionHandler gets called OK. 因此,completionHandler被称为OK。 In the S3 console, the url to the file I am trying to download starts with " https://s3.amazonaws.com/ /xxx/xxx.tiff".
在S3控制台中,我要下载的文件的URL以“ https://s3.amazonaws.com/ /xxx/xxx.tiff”开头。 Does anyone have an idea as to what the problem is here?
有谁知道这里的问题是什么?
It sounds like both your identity pool and your S3 bucket are in the us-west-2 region. 听起来您的身份池和S3存储桶都在us-west-2地区。 You addressed the identity pool part on yourself, and that is correct.
您自己解决了身份池问题,这是正确的。 In order to fix the bucket region on your code, you need to pass the region to the S3 call too, otherwise it will use the default of us-east-1 and give you that error.
为了在代码上修复存储桶区域,您还需要将该区域传递给S3调用,否则它将使用默认的us-east-1并给您该错误。
An alternative would be to specify your url with [bucketname].s3.amazonaws.com, some people seemed to have success with that, but it will probably by just fixing the region. 一种替代方法是使用[bucketname] .s3.amazonaws.com指定您的网址,有些人似乎已经成功了,但是可能仅通过固定区域即可。
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityPoolId:@"us-west-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"];
It is correct but you need to add some line of code. 没错,但是您需要添加一些代码行。 Please add this code:
请添加以下代码:
NSString *cognitoId = credentialsProvider.identityId;
NSString *cognitopoolId = credentialsProvider.identityPoolId;
NSLog(@"This is cognitoId: %@",cognitoId);
NSLog(@"This is cognitopoolId: %@",cognitopoolId);
[[credentialsProvider getIdentityId] continueWithBlock:^id(AWSTask *task){
if (task.error == nil) {
NSString* cognitoId = credentialsProvider.identityId;
NSLog(@"cognitoId: %@", cognitoId);
} else {
NSLog(@"Error : %@", task.error);
}
return nil;
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.