我在我的项目中使用xcode 6.4。问题是我遇到了一些与AWS S3(Amazon Web Services S3)有关的问题。我需要做的是从存储桶中下载文件。它说没有找到标识池ID,但已经多次检查它,完全在控制台内部。尝试下载文件时收到此错误消息。
2015-10-01 14:44:09.470 XXXXX[9842:360833] AWSiOSSDKv2 [Error] AWSIdentityProvider.m line:185 | __51-[AWSAbstractCognitoIdentityProvider getIdentityId]_block_invoke169 | GetId failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=12 "The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 12.)" UserInfo=0x7ff56b0f1260 {__type=ResourceNotFoundException, message=IdentityPool 'ap-northeast-1:a4ef1695-XXXX-4e7c-XXXX-56f2a09eXXXX' not found.}]
2015-10-01 14:44:09.471 XXXXX[9842:360833] AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:527 | __40-[AWSCognitoCredentialsProvider refresh]_block_invoke352 | Unable to refresh. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=12 "The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 12.)" UserInfo=0x7ff56b0f1260 {__type=ResourceNotFoundException, message=IdentityPool 'ap-northeast-1:a4ef1695-XXXX-4e7c-XXXX-56f2a09eXXXX' not found.}]
AppDelegate.swift
import UIKit
import CoreData
import AWSS3
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var cognitoIdentityPoolId: String = "ap-northeast-1:a4ef1695-XXXX-4e7c-XXXX-56f2a09eXXXX"
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let credentialsProvider = AWSCognitoCredentialsProvider(regionType: AWSRegionType.APNortheast1, identityPoolId: cognitoIdentityPoolId)
let defaultServiceConfiguration = AWSServiceConfiguration(
region: AWSRegionType.APNortheast1, credentialsProvider: credentialsProvider)
AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = defaultServiceConfiguration
return true
}
/* -- */
}
ViewController.swift
import UIKit
import AWSS3
class ViewController: UIViewController{
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
override func viewDidLoad() {
super.viewDidLoad()
var downloadingFilePath: NSString = NSTemporaryDirectory().stringByAppendingPathComponent("downloaded-myImage.gif")
var downloadingFileURL: NSURL = NSURL.fileURLWithPath(downloadingFilePath as String)!
var downloadRequest = AWSS3TransferManagerDownloadRequest()
downloadRequest.bucket = "xxxxxx-stg/events"
downloadRequest.key = "myImage.gif"
downloadRequest.downloadingFileURL = downloadingFileURL
transferManager.download(downloadRequest).continueWithSuccessBlock({
(task: AWSTask!) -> AWSTask! in
dispatch_async(dispatch_get_main_queue(), {
println("test")
})
return nil
})
}
}
是关于IAM策略问题还是需要设置自定义身份验证提供程序?
参考:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
答案 0 :(得分:3)
确保您已设置IAM政策。它在IAM下 - >角色 - >内联政策 - >编辑政策。它看起来应该与此类似:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"s3:*"
],
"Resource": [
"*"
]
}
]
}
答案 1 :(得分:1)
我已经得到了答案。我像这样更新IAM政策
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*"
],
"Resource": [
"*"
]
}
]
}
并允许Unauthenticated Access
。
答案 2 :(得分:0)
我通过将“ AmazonS3ReadOnlyAccess”策略附加到我尝试使用的IAM实体(包括未认证角色)来解决了这个问题。如果您所构建的内容还可以,您还可以附加“ AmazonS3FullAccess”策略。这些策略可以在IAM页面的“策略”标签中找到。