Textract using Javascript in browser - Unable to connect

0

I am trying to configure Textract to use the AnalyzeId method for my web application. I created an Identity Pool in Cognito, applied the 'AmazonTextractFullAccess' policy to the Unauth role, and got the region and PoolId for the role. When I use the following line to import the SDK, I get the following error:

AWS.Textract is not a constructor

So I decided to build my own SDK with the SDK Builder. I included AWS.Textract and AWS.CognitoIdentity. When I do this, I get the following error:

AccessDeniedException: User: arn:aws:sts::554864403737:assumed-role/Cognito_KripkeRetailUnauth_Role/CognitoIdentityCredentials is not authorized to perform: textract:AnalyzeID because no session policy allows the textract:AnalyzeID action

I'm not sure what I am doing wrong and have been unable to find a solution so far. Any help would be appreciated. Thanks.

Javascript:

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.410.0.min.js"></script>
<script language="JavaScript">
AWS.config.region = 'us-east-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
     IdentityPoolId: 'us-east-2:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
});
var textract = new AWS.Textract();

var params = {
     DocumentPages: [ 
     {
        Bytes: <<image>>
      },
  ]
};
            
textract.analyzeID(params, function(err, data) {
     if (err) console.log(err, err.stack); // an error occurred
     else     console.log(data);           // successful response
     });
        } 
    );
}
</script>
  • There is something with the IAM Unauth role that is causing this, please post the policy document if possible. However, instead of going this route I would highly recommend taking a look at this example which uses SDK V3 where you get the latest features like Textract queries. This is assuming you are building your web-app using NPM or Yarn and web bundler like webpack which will take care of the bundling for you.

  • How do I post the policy document? Also, unfortunately I'm not using NPM or Yarn with my web app. That's the reason I am using V2 of the Javascript SDK.

1 Answer
0

Can you try using the latest SDK version -

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1185.0.min.js"></script>

Additionally, the authentication role in Cognito Identity Pool should have Textract actions allowed. Is that assumed unauth role allowing it?

answered 2 years ago
  • Thanks for answering. When I use the script line in your answer, I get 'AWS.Textract is not a constructor'. I have added 'AmazonTextractFullAccess' to the Unauth role I am using. Any ideas? Thanks!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions