我是新的处理AWS web服务,我正在使用开放身份发送DeveloperAuthProviderName和Token在AWSCognitoCredentialsProvider类的登录字典中,然后在一个视图控制器中,我调用lambda函数,它给我下面的错误。我使用CognitoSyncDemo应用程序,也尝试通过pod导入所有框架,但结果是相同的。请帮我解决这个问题。
AWSiOSSDKv2 [Error] AWSCredentialsProvider。[AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:]_block_invoke | GetCredentialsForIdentity失败。错误是[Error Domain=com.amazonaws]。AWSCognitoIdentityErrorDomain Code=7 "操作无法完成。"(com.amazonaws。AWSCognitoIdentityErrorDomain错误7.)UserInfo=0x1700778c0 {__type=InvalidParameterException, message=请提供一个有效的公共提供者}]
这是Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
AWSCognitoCredentialsProvider *credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:AWSRegionUSEast1 identityId:IdentityId identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1
credentialsProvider:credentialsProvider];
[[AWSServiceManager defaultServiceManager] setDefaultServiceConfiguration:configuration];
return YES;
}
这是viewController中viewDidLoad的代码。
-(void)setUpCredentials{
//initWithRegionType:CognitoRegionType identityId:IdentityId identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}
AZCDeveoper class inherit AWSEnhancedCognitoIdentityProvider class
AZCDeveloper * identity = [[AZCDeveloper alloc] initWithRegionType:CognitoRegionType identityId:IdentityId accountId:nil identityPoolId:CognitoIdentityPoolId logins:@{DeveloperAuthProviderName:Token}];
credentialsProvider = [[AWSCognitoCredentialsProvider alloc] initWithRegionType:CognitoRegionType
identityProvider:identity
unauthRoleArn:nil
authRoleArn:nil];
// [identity refresh];
}
这是在某个点击
时调用的lambda函数-(void)lamdaInvoker{
AWSLambdaInvoker *lambdaInvoker = [AWSLambdaInvoker defaultLambdaInvoker];
NSLog(@"LamdaInvoker:%@",lambdaInvoker);
[[lambdaInvoker invokeFunction:@"Hello"
JSONObject:@{@"": @""}] continueWithBlock:^id(BFTask *task) {
if (task.error) {
NSLog(@"Error: %@", task.error);
if ([task.error.domain isEqualToString:AWSLambdaInvokerErrorDomain]
&& task.error.code == AWSLambdaInvokerErrorTypeFunctionError) {
NSLog(@"Function error: %@", task.error.userInfo[AWSLambdaInvokerFunctionErrorKey]);
}
}
if (task.exception) {
NSLog(@"Exception: %@", task.exception);
}
if (task.result) {
NSLog(@"Result: %@", task.result);
dispatch_async(dispatch_get_main_queue(), ^{
});
}
return nil;
}];
}
他们从你的问题,我将采取的方法是集中在错误的部分说getcredentialsforidentity。我对AWS也比较陌生,我认为我遇到错误的一半时间,都是因为我在凭证方面做错了。我要确保IAM用户有必要的凭据,以便调用lambda函数。
如果你认为你有正确的位置,那么我要确保你设置你的配置是正确的。