Lambda function issue in AWS iOS Sdk

南楼画角 提交于 2019-12-12 04:07:06

问题


I'm new to deal with AWS web services, i'm working with open-identity sending DeveloperAuthProviderName and Token in login dictionary of AWSCognitoCredentialsProvider class and then in a viecontroller i'm invoking a lambda funtion and its giving me error below. I have used CognitoSyncDemo App and also tried with importing all frameworks through pod but result is same. Please help me out of this.

AWSiOSSDKv2 [Error] AWSCredentialsProvider.m line:435 | __73-[AWSCognitoCredentialsProvider getCredentialsWithCognito:authenticated:]_block_invoke | GetCredentialsForIdentity failed. Error is [Error Domain=com.amazonaws.AWSCognitoIdentityErrorDomain Code=7 "The operation couldn’t be completed. (com.amazonaws.AWSCognitoIdentityErrorDomain error 7.)" UserInfo=0x1700778c0 {__type=InvalidParameterException, message=Please provide a valid public provider}]

This is 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;
}

This is the code in viewDidLoad in a viewController.

-(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];

}

This is the lambda function invoked on a certain click

-(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;
    }];


}

回答1:


hey from your question the approach I would take is focusing on the portion of the error that saysGetCredentialsForIdentity. I'm relatively new to AWS as well and I think that half the time I've encountered an error, it was because there was something about credentials that I was doing wrong. I'd make sure that the IAM user has the necessary credentials in order to invoke the lambda function.

If you think that you have that all correctly placed, then I'd make sure that you are setting up your configuration correctly.



来源:https://stackoverflow.com/questions/31354780/lambda-function-issue-in-aws-ios-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!