简体   繁体   English

AWS S3:桶区域和identityPoolId(Swift)上的混淆

[英]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: 这似乎是两个问题之一,但我无法确定是哪一个:

  1. Problem with my identityPoolId 我的identityPoolId问题
  2. Problem with the region for the bucket 铲斗区域的问题

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.

相关问题 快速上传图像 AWS S3 存储桶 - Upload image AWS S3 bucket in swift 将图像上传到AWS S3的瞬间从另一个区域失败,但如果与存储桶位于同一区域,则成功上传 - Image upload to AWS S3 fails instantly from a different region but succeeds if in the same region as the bucket 如何使用AWS移动中心创建的s3存储桶将文件从Swift上传到受保护的s3存储桶? - How do I upload a file into a protected s3 bucket from Swift using the s3 bucket created by AWS mobile hub? 快速上传到s3存储桶并没有结束 - Swift upload to s3 bucket does not end 列出AWS S3存储桶中的所有对象 - List all objects in AWS S3 bucket 在AWS socket S3存储桶中进行缓存 - Caching in AWS socket S3 bucket 如何使用未经身份验证的用户从 Swift 中的 AWS S3 存储桶下载文件 - How to download file from an AWS S3 bucket in Swift with unauthenticated users 上传到S3 bucket Swift 3问题 - Uploading to S3 bucket Swift 3 issue Swift - 将视频转换为数据,字符串使用 UTF8 编码返回 nil - 通过 HTTP 发送视频到 AWS S3 存储桶 - Swift - converting video to data and String returns nil with UTF8 encoding - sending video via HTTP POST to AWS S3 bucket 如何将我的ios应用程序中的图像上传到存储在aws s3上的存储桶中,并在Swift中完成所有这些操作? - How can I upload an image from my ios app to my bucket stored on aws s3 and do all of that in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM