aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 884 forks source link

awsconfiguration.json for Textract #1948

Closed bluepixeltech closed 5 years ago

bluepixeltech commented 5 years ago

State your question Hi,

I am trying to use Textract in Swift. I have added the AWSTextract to the project using cocoapods. I have also added a user with AmazonTextractFullAccess, AdministratorAccess and AmazonTextractServiceRole permissions in IAM AWS console. Yet I receive:

'The service configuration is nil. You need to configure awsconfiguration.json, Info.plist or set defaultServiceConfiguration before using this method.'

I have also setup AppSync according to the guide on Amplify and it is working. My guess is that the corresponding field for AWSTextract should be added to the awsconfiguration.json too. Right now, the only item in awsconfiguration.json is the one for AppSync. I appreciate if someone can help me to figure this out.

Which AWS Services are you utilizing? AWSTextract Provide code snippets (if applicable)

let encodedImage = image.toBase64() let textractClient = AWSTextract.default() let request: AWSTextractDetectDocumentTextRequest = AWSTextractDetectDocumentTextRequest() let document = AWSTextractDocument() document?.bytes = encodedImage?.data(using: .utf8) request.document = document textractClient.detectDocumentText(request) { (response, error) in guard let response = response else { return } print("Response: (String(describing: response.blocks))") }

Environment(please complete the following information):

Device Information (please complete the following information):

If you need help with understanding how to implement something in particular then we suggest that you first look into our developer guide. You can also simplify your process of creating an application, as well as the associated backend setup by using the Amplify CLI.

lawmicha commented 5 years ago

Hi @bluepixeltech ,

Thanks for reaching out. I see in here https://github.com/aws-amplify/aws-sdk-ios/issues/1838#issuecomment-536805145 you were able to get an error about exceeding the limits. I assume you were able to get it running then?

There's a task open for adding documentation here https://github.com/aws-amplify/aws-sdk-ios/issues/1622 that you can track as well

AWS Amplify CLI is used to provision your backend resources and will generate a awsconfiguration.json. AWS Textract SDK does not support awsconfiguration.json directly, however there are a few things to know about this.

The reason why you can use Amplify CLI to configure predictions category is because there is a library built for JS. you can see here it uses Predictions from aws-amplify JS SDK, which uses AWS Textract internally. (https://aws-amplify.github.io/docs/js/predictions)

So the guidance for using AWS Textract will be to follow the AWS Textract documentation on getting started (https://docs.aws.amazon.com/textract/latest/dg/getting-started.html) and then in code

  1. configure AWSCognitoCredentialsProvider
  2. Create an AWSServiceConfiguration using the AWSCognitoCredentialsProvider
  3. Set the AWSServiceManager's defaultServiceConfiguration to the AWSServiceConfiguration

Then you should be able to call AWSTextract.default()

Another note is that, if you want, you could leverage AWS Amplify CLI to create resources for Predictions and reuse the values from awsconfiguration.json in your configuration for AWS Textract

Can you let us know how you are currently configuring it?

Thanks, Michael

bluepixeltech commented 5 years ago

Thanks for reaching out. I finally made it work. The problem was that a role which was used by Textract didn't have permission to can detectDocumentText. The problem was resolved after assigning Textract permissions.