Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crtError with Predictions, delegate provider failed. #3284

Closed
Slydune opened this issue Oct 6, 2023 · 7 comments
Closed

crtError with Predictions, delegate provider failed. #3284

Slydune opened this issue Oct 6, 2023 · 7 comments
Assignees
Labels
predictions Issues related to the Predictions category question General question

Comments

@Slydune
Copy link

Slydune commented Oct 6, 2023

Describe the bug

Error:crtError(AwsCommonRuntimeKit.CRTError(code: 6167, message: "Valid credentials could not be sourced by the delegate provider", name: "AWS_AUTH_CREDENTIALS_PROVIDER_DELEGATE_FAILURE"))

Happens whenever attempting to execute the below code

func detectText(_ image: URL) async throws -> [Predictions.IdentifiedWord]? {
    do {
//        let options = Predictions.Identify.Options(defaultNetworkPolicy: .offline)
        let result = try await Amplify.Predictions.identify(.text, in: image)
        var rawText : String = ""
        try result.rawLineText?.forEach{rawText+=(" "+$0)}
        print("Identified text: \(rawText)")
        return result.words
    }  catch let error as PredictionsError {
        print("Error identifying text: \(error)")
        throw error
    } catch {
        print("Unexpected error: \(error)")
        throw error
    }
  }

That is called in this button

struct ContentView: View {
    var body: some View {
        VStack {
            Button {
                let u = URL(filePath: "/Users/somethinguser/Documents/aisles/aisles/HelloWorld.svg.png")
                Task {
                    let results = try await aisles.detectText(u)
                }
            } label: {
                Text("TEST").font(.system(size:36))
            }
            .buttonStyle(.bordered)
            
        }
        .padding()
    }
}

Steps To Reproduce

Execute the above code on the Xcode simulator.

Expected behavior

Expected a normal predictions run with a return value.

Amplify Framework Version

2.0.0

Amplify Categories

Predictions

Dependency manager

Swift PM

Swift version

5

CLI version

12.6.0

Xcode version

14.3.1

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Platforms

iOS

OS Version

iOS 16

Device

Iphone 14 Pro

Specific to simulators

No response

Additional context

No response

@thisisabhash thisisabhash added predictions Issues related to the Predictions category auth Issues related to the Auth category bug Something isn't working labels Oct 6, 2023
@ruisebas
Copy link
Member

ruisebas commented Oct 6, 2023

Hi @Slydune, thanks for opening this issue.

I was unable to reproduce it on the latest Amplify version, 2.19.0 (you stated you are using 2.0.0, however Predictions is not available in said version). I used your code snippet and successfully got a result.

I suspect there's some misconfiguration going on. Are you doing any sort of custom authentication in your app, or are you just using what's provided by AWSCognitoAuthPlugin?

In any case, could you please share:

  • Your amplifyconfiguration.json file, with sensitive information removed?
  • The verbose logs when you get this error. You can enable them by calling:
    Amplify.Logging.logLevel = .verbose

That will help us identify what could be causing your issue.

Thanks!

@ruisebas ruisebas added pending-community-response Issue is pending response from the issue requestor and removed auth Issues related to the Auth category labels Oct 6, 2023
@Slydune
Copy link
Author

Slydune commented Oct 10, 2023

amplifyconfiguration.json

{
    "UserAgent": "aws-amplify-cli/2.0",
    "Version": "1.0",
    "auth": {
        "plugins": {
            "awsCognitoAuthPlugin": {
                "UserAgent": "aws-amplify/cli",
                "Version": "0.1.0",
                "IdentityManager": {
                    "Default": {}
                },
                "CredentialsProvider": {
                    "CognitoIdentity": {
                        "Default": {
                            "PoolId": "us-east-1:pool id",
                            "Region": "us-east-1"
                        }
                    }
                },
                "CognitoUserPool": {
                    "Default": {
                        "PoolId": "us-east-1poolid,
                        "AppClientId": "appclientid",
                        "Region": "us-east-1"
                    }
                },
                "Auth": {
                    "Default": {
                        "authenticationFlowType": "USER_SRP_AUTH",
                        "socialProviders": [],
                        "usernameAttributes": [],
                        "signupAttributes": [
                            "EMAIL"
                        ],
                        "passwordProtectionSettings": {
                            "passwordPolicyMinLength": 8,
                            "passwordPolicyCharacters": []
                        },
                        "mfaConfiguration": "OFF",
                        "mfaTypes": [
                            "SMS"
                        ],
                        "verificationMechanisms": [
                            "EMAIL"
                        ]
                    }
                }
            }
        }
    },
    "predictions": {
        "plugins": {
            "awsPredictionsPlugin": {
                "defaultRegion": "us-east-1",
                "identify": {
                    "identifyText": {
                        "format": "ALL",
                        "region": "us-east-1",
                        "defaultNetworkPolicy": "auto"
                    }
                }
            }
        }
    }
}

I am only using AWSCognitoAuthPlugin for authentication.

Where would the verbose logs end up? The change of the logging value resulted in the same as above output in my console.

@ruisebas
Copy link
Member

Thanks for providing the amplifyconfiguration.json file. The verbose logs are also printed on the console, but I forgot to mention you should enable them before calling Amplify.configure().
Please share the full logs with us, i.e. also whatever is printed before you get the error.

Some additional questions:

  • When you get the error, are you signed in or using a guest user? Or does it happen in both?
  • What Amplify version you are using? You can see it in Xcode in the Project Navigator under Package Dependencies

Thanks!

@Slydune
Copy link
Author

Slydune commented Oct 10, 2023

Log

Is user signed in - false
Error identifying text: PredictionsError: A service error occurred with message:An unknown error type was thrown by the service.
Recovery suggestion: This should never happen. There is a possibility that there is a bug if this error persists.
Please take a look at https://github.com/aws-amplify/amplify-ios/issues to see if there are any
existing issues that match your scenario, and file an issue with the details of the bug if there isn't.
Caused by:
client(ClientRuntime.ClientError.retryError(ClientRuntime.SdkError<AWSRekognition.DetectTextOutputError>.service(AWSRekognition.DetectTextOutputError.accessDeniedException(AWSRekognition.AccessDeniedException(_headers: Optional(Content-Type: application/x-amz-json-1.1, 
x-amzn-RequestId: , 
Content-Length: 282, 
Connection: close, 
Date: Tue, 10 Oct 2023 22:30:35 GMT), _statusCode: Optional(http_status_400), _message: Optional("User: arn:aws:sts::assumed-role/unauthRole/CognitoIdentityCredentials is not authorized to perform: rekognition:DetectText because no identity-based policy allows the rekognition:DetectText action"), _requestID: Optional(""), _retryable: false, _isThrottling: false, _type: ClientRuntime.ErrorType.client, code: nil, logref: nil, message: Optional("User: unauthRole/CognitoIdentityCredentials is not authorized to perform: rekognition:DetectText because no identity-based policy allows the rekognition:DetectText action"))), 
Status Code: http_status_400 
 Connection: close 

I am only attempting with guest and only plan to use guest in the future, rechecked my package dependencies (Wasn't sure how to read SPM at first) and its showing me on current major version so 2.19.0 if I looked correctly.

I did reconfigure my guest auth path and am now here, I realize this isn't the initial error but would still appreciate some help if you could point me in the right direction.

@ruisebas
Copy link
Member

Based on the error message:

User: unauthRole/CognitoIdentityCredentials is not authorized to perform: rekognition:DetectText because no identity-based policy allows the rekognition:DetectText action

it seems that your backend is not correctly configured. It could be that maybe you did not select Auth and Guest users while setting up the category. Or perhaps there was a problem with the deployment during amplify push.

Please try configuring again and check that you don't get any errors when running the CLI commands.

@Slydune
Copy link
Author

Slydune commented Oct 17, 2023

Thanks for the info I've got it all figured out now. Was wondering if there is a way to force Textract vs Recognition when using predictions. I know there's an option for forcing internal iOS usage but don't see one for which AWS service to use. If not what's the deciding factor on which it is processed by?

@atierian atierian added question General question and removed bug Something isn't working pending-community-response Issue is pending response from the issue requestor labels Oct 17, 2023
@atierian
Copy link
Member

Using .textInDocument will use always use Amazon Textract. For example:

let result = try await Amplify.Predictions.identify(
  .textInDocument(textFormatType: .all), 
  in: image
)

Here's the applicable documentation.

Using .text (like in your example above) will always use Amazon Rekognition, and may also use Textract depending on the amount of text identified by Rekognition. There's not currently a way to specify that one service is used and not another. If having the ability to specify which service is used for .text requests would be helpful for you, we'd love to hear more about your use case.

@ruisebas ruisebas added pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Oct 20, 2023
@github-actions github-actions bot removed pending-community-response Issue is pending response from the issue requestor closing soon This issue will be closed in 7 days unless further comments are made. labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
predictions Issues related to the Predictions category question General question
Projects
None yet
Development

No branches or pull requests

4 participants