从AWS DynamoDB iOS

时间:2017-06-29 09:17:27

标签: ios amazon-web-services amazon-dynamodb

我在我的应用中使用了AWS DynamoDB。我使用AWSDynamoDBObjectMapper从数据库中获取记录,但每次都获得InvalidIdentityPoolConfigurationException。我在info.pilist中设置了poolId和region,

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.}]

任何人都可以了解上述错误吗?上面的代码中是否缺少任何配置?

1 个答案:

答案 0 :(得分:0)

<强> 1。在Cognito Console中添加Facebook作为身份验证提供程序。

我可以看到您使用Facebook进行身份验证。在AWS Cognito Console中,在创建身份池时,您必须在&#34;身份验证提供程序&#34;下添加Facebook App ID。 - &GT; &#34; Facebook和#34;

<强> 2。添加足够的权限和角色。

创建池后,您必须使用标识池附加角色,并且角色应具有足够的IAM权限。

例如,如果要执行查询,则附加到标识池的角色的策略文档应包含以下行:

"Action": [
     "dynamodb: Query"
]

您必须为要执行的DynamoDB操作添加适当的操作。