iOS AWS S3未经身份验证的访问

时间:2018-10-29 12:56:28

标签: amazon-s3

我正在尝试将图像资源从我的应用程序上传到S3存储桶:

  • 功能性:应用程序用户通过自定义应用程序身份验证在应用程序中进行身份验证,然后他们可以创建带有图像资源的帖子。
  • 技术:我已经设置了一个公共访问S3存储桶(欧盟巴黎区域),并在其中上传了应用程序用户资源。

我还创建了具有未经身份验证的访问权限的Cognito身份池,然后更新了IAM Unauth_Role以添加新的自定义策略:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": "arn:aws:s3:::#BUCKET_NAME#/*"
        }
    ]
}

然后在ios项目中,我安装了Pod AWSS3。 在AppDelegate中,此方法在didFinishLaunchingWithOptions中调用:

fileprivate func configureAWS()
{
    AWSDDLog.sharedInstance.logLevel = .verbose

    let credentialsProvider:AWSCognitoCredentialsProvider =
        AWSCognitoCredentialsProvider(regionType:AWSRegionType.USEast1,
                                      identityPoolId: "#POOL_ID#")

    let configuration = AWSServiceConfiguration(region:AWSRegionType.USEast1, credentialsProvider:credentialsProvider)

    AWSServiceManager.default().defaultServiceConfiguration = configuration
}

然后在我的控制器中,我开始上传:

if let urlImagePath = localFileURL,
    let uploadRequest = AWSS3TransferManagerUploadRequest() {
        [uploadRequest configuration…]
}

最后启动请求:

 AWSS3TransferManager.default().upload(uploadRequest).continueWith(executor: AWSExecutor.immediate(), block: { (task) -> Any? in
    if let error = task.error {
        print("❌ Upload image failed with error: (\(error.localizedDescription))")
    completionHandler(false)
    return nil
    }
}

task.error不是nil,我收到以下消息:

Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=10 "(null)" UserInfo={__type=ResourceNotFoundException, message=IdentityPool 'us-east-1:d4e0d542-089f-4fb4-83be-93946576bc00' not found.}

0 个答案:

没有答案