Amplify-js: Prediction Identify plain text requests failed when response lasts more than 10 seconds

Created on 15 Jun 2020  Â·  12Comments  Â·  Source: aws-amplify/amplify-js

Env : react native

"aws-amplify": "^3.0.8",
"aws-amplify-react-native": "^4.0.4",
"react": "16.11.0",
"react-native": "0.62.2",

Prediction Identify plain text Works fine with image stored in S3 with few texts.
But when I increase the number ok texts to be detected i get always a "Network request failed" with an "Unhandle Promise Rejection" after almost 10 seconds. Is there a way to get around this issue.

It doesn't depend on the size of the image.
And it works fine when I test the same image on the textRact console.

My code is very simple :

```
await Predictions.identify({
text: {
source: {
key: "test.jpg",
level: "public"
},
format: "PLAIN"
}
})
.then((res) => setPrediction(JSON.stringify(res, null, 2)))
.catch((err) =>
setPrediction("Predictions error : " + JSON.stringify(err, null, 2))

``` );
}

Predictions React Native pending-close-response-required

Most helpful comment

@Ashish-Nanda Region setting is an essential point.
Thanks to @cedricgrothues Despite an unvailable region, I clearly understrand the problem and the reason why it partially works because of the switch between rekognition and textract.

I actually use eu-central-1 but I can't try a valid region for my production application because of another issue between S3 and Prediction Region.
It seems Prediction use his own region setting to request S3 rather than the Amplify storage setting region (aws_user_files_s3_bucket_region).
Has I reported here : https://github.com/aws-amplify/amplify-js/issues/5560#issue-606802156
prediction failed if the file to be analysed isn't in the same S3 region. (Another issue was identified into the unability to use the private storage)
So it would be wonderful if this S3 / Prediction region issue could be resolved.

All 12 comments

Hi @mlafo, thank you for the report! I am able to reproduce the behavior you are seeing.

Using an image with just a few words works as expected, but when using an image that contains a few sentences (see example below) the response is undefined and an uncaught exception is thrown.

fetch-http-handler.js:46 POST https://textract.eu-central-1.amazonaws.com/ net::ERR_NAME_NOT_RESOLVED

AmazonAIIdentifyPredictionsProvider.js:201 Uncaught (in promise) TypeError: Failed to fetch

This is the image I used:
text-long

@mlafo – from what I can tell, this is an issue with @aws-sdk/client-textract.

Using Predictions with images containing fewer than fifty words works fine because for that amplify-js uses rekognition (see AmazonAIIdentifyPredictionsProvider.ts line 178), but if an image contains fifty or more words, amplify-js uses textract.

Here is the rekognition endpoint (which works as expected):

curl -X POST https://rekognition.eu-central-1.amazonaws.com/

> Connected to rekognition.eu-central-1.amazonaws.com (3.124.237.132) port 443

And here the textract endpoint:

curl -X POST https://textract.eu-central-1.amazonaws.com/

> curl: (6) Could not resolve host: textract.eu-central-1.amazonaws.com

This happens because textract instances are currently only available in eu-west-1, eu-west-2, ap-southeast-1, ap-southeast-2, us-east-1, us-east-2, us-west-1 and us-west-2, but the aws-sdk assumes that there are a lot more valid regions.

As @cedricgrothues has mentioned, this seems to be a limitation from the service itself. Not specific to Amplify. I will close this issue, if you have further comments or clarification that needs to answered. Feel free to ping and I can reopen the issue.

@mlafo what region are you using in your config currently? Could you try making a request to one of the valid regions listed here to see if it works.

Also when using the CLI to add Predictions category with Identify Text, did you enable document detection as well? You would need to enable that in order to call Textract.
https://docs.amplify.aws/lib/predictions/identify-text/q/platform/js#set-up-the-backend

@cedricgrothues Could you comment on this too? How did you set it up?

@Ashish-Nanda Region setting is an essential point.
Thanks to @cedricgrothues Despite an unvailable region, I clearly understrand the problem and the reason why it partially works because of the switch between rekognition and textract.

I actually use eu-central-1 but I can't try a valid region for my production application because of another issue between S3 and Prediction Region.
It seems Prediction use his own region setting to request S3 rather than the Amplify storage setting region (aws_user_files_s3_bucket_region).
Has I reported here : https://github.com/aws-amplify/amplify-js/issues/5560#issue-606802156
prediction failed if the file to be analysed isn't in the same S3 region. (Another issue was identified into the unability to use the private storage)
So it would be wonderful if this S3 / Prediction region issue could be resolved.

@ashika01 @Ashish-Nanda I tried using textract in a supported region (eu-west-1) without enabling it, but that caused an AccessDeniedException not a network error.

@cedricgrothues Do you use Storage for your file ?
If yes, is the region in eu-west-1 too ?

@cedricgrothues Thanks for checking it out. @mlafo I think cedric is already looking at that issue you opened up.

@mlafo – Both my S3 bucket and predictions are in eu-west-1.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DougWoodCDS picture DougWoodCDS  Â·  3Comments

simon998yang picture simon998yang  Â·  3Comments

cosmosof picture cosmosof  Â·  3Comments

oste picture oste  Â·  3Comments

guanzo picture guanzo  Â·  3Comments