0

I am using user pools with my iOS mobile app.

I would like to access my lambda functions using the sdk but can't find documentation on how to provide the authentication necessary. Also unclear as to whether I need to use the API Gateway if I am using the sdk with user pools.

I am using this method to access my lambda function:

private func invokeLambda(data: [String: Any]) {

    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let pool = appDelegate.pool
    let credentialsProvider = AWSCognitoCredentialsProvider(regionType: .USEast1, identityPoolId: "MyIdentityPoolId", identityProviderManager:pool)
    let configuration = AWSServiceConfiguration(region:.USEast1,     credentialsProvider:credentialsProvider)
    AWSServiceManager.default().defaultServiceConfiguration = configuration

    let lambdaInvoker = AWSLambdaInvoker.default()

    let jsonObject: [String: Any] = data

    lambdaInvoker.invokeFunction("myFunction", jsonObject: jsonObject).continueWith(block: {(task:AWSTask<AnyObject>) -> Any? in
        if let error = task.error as NSError? {
            if (error.domain == AWSLambdaInvokerErrorDomain) && (AWSLambdaInvokerErrorType.functionError == AWSLambdaInvokerErrorType(rawValue: error.code)) {
                print("Function error: \(error.userInfo[AWSLambdaInvokerFunctionErrorKey])")
            } else {
                print("Error: \(error)")
            }
            return nil
        }
        // Handle response in task.result
        if let JSONDictionary = task.result as? NSDictionary {
            print("Result: \(JSONDictionary)")
            print("resultKey: \(JSONDictionary["resultKey"])")
        }
        return nil
    })
}

I am getting the following error:

"AccessDeniedException"

Edit #1

The error that I am getting indicates the unauth role is being used for access rather than the auth role. the user is correctly logged in and the token is valid. Not sure where I am going wrong here.

alionthego
  • 8,508
  • 9
  • 52
  • 125

1 Answers1

0

Try attaching AWSLambdaInvocation-DynamoDB to the role.

adimona
  • 109
  • 2
  • 15