2017-06-29 29 views
0

我在我的應用程序中使用了AWS DynamoDB。我正在使用AWSDynamoDBObjectMapper從數據庫中獲取記錄,但每次都獲取InvalidIdentityPoolConfigurationException。我已成立poolId和info.pilist區域,從AWS DynamoDB重新獲取記錄時獲取InvalidIdentityPoolConfigurationException iOS

enter image description here

以下是我的代碼,

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 
                           identityPoolId:IDENTITY_POOL_ID]; 



AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast2 
                    credentialsProvider:credentialsProvider]; 

AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration; 

AWSDynamoDBObjectMapperConfiguration *objectMapperConfiguration = [[AWSDynamoDBObjectMapperConfiguration alloc] init]; 
[AWSDynamoDBObjectMapper registerDynamoDBObjectMapperWithConfiguration:configuration objectMapperConfiguration:objectMapperConfiguration forKey:@"USEast1DynamoDBObjectMapper"]; 
_dynamoDBObjectMapper = [AWSDynamoDBObjectMapper DynamoDBObjectMapperForKey:@"USEast1DynamoDBObjectMapper"]; 
return YES; 
} 

DynamoDBManager.m

+(void)loginWithFaceBook:(NSString*)fbId{ 

AWSDynamoDBScanExpression *scanExpression = [AWSDynamoDBScanExpression new]; 
scanExpression.filterExpression = @"facebook_id = :val"; 
scanExpression.expressionAttributeValues = @{@":val":fbId}; 

[[AppContext.dynamoDBObjectMapper scan:[dynamo_user class] 
       expression:scanExpression] 
continueWithBlock:^id(AWSTask *task) { 
    if (task.error) { 
     NSLog(@"The request failed. Error: [%@]", task.error); 
    } else { 
     // AWSDynamoDBPaginatedOutput *paginatedOutput = task.result; 
     NSLog(@"The request sucesss. Result : [%@]", task.result); 

    } 
    return nil; 
}]; 

}

MyViewController.m

[DynamoDBManager loginWithFaceBook:[result valueForKey:@"id"]]; 

下面是我的錯誤:

The request failed. Error: [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=5 "(null)" UserInfo={__type=InvalidIdentityPoolConfigurationException, message=Invalid identity pool configuration. Check assigned IAM roles for this pool.}] 

可以在具有對上述錯誤想法的人?上述代碼中缺少任何配置嗎?

回答

0

1.在Cognito控制檯中添加Facebook作爲身份驗證提供程序。

我可以看到您正在使用Facebook進行身份驗證。在AWS Cognito控制檯中,創建身份池時,必須在「身份驗證提供程序」 - >「Facebook」下添加Facebook應用程序ID

2.添加足夠的權限和角色。

創建池後,您必須將角色與標識池相關聯,並且角色應具有足夠的IAM權限。

例如,如果你想執行一個查詢,附加到身份池的作用的政策文件應具有以下行:

"Action": [ 
    "dynamodb: Query" 
] 

你必須添加對相應的操作您要執行的DynamoDB操作。