Configuring Amazon Textract for Asynchronous Operations - Amazon Textract

Configuring Amazon Textract for Asynchronous Operations

The following procedures show you how to configure Amazon Textract for use with an Amazon SNS topic and an Amazon SQS queue.


If you're using these instructions to set up the Detecting or Analyzing Text in a Multipage Document example, you don't need to do steps 3, 4, 5, and 6. The example includes code to create and configure the Amazon SNS topic and Amazon SQS queue.

To configure Amazon Textract

  1. Set up an AWS account to access Amazon Textract. For more information, see Step 1: Set Up an AWS Account and Create an IAM User.

    Ensure that the user has at least the following permissions:

    • AmazonTextractFullAccess

    • AmazonS3ReadOnlyAccess

    • AmazonSNSFullAccess

    • AmazonSQSFullAccess

  2. Install and configure the required AWS SDK. For more information, see Step 2: Set Up the AWS CLI and AWS SDKs.

  3. Create an Amazon SNS topic. Prepend the topic name with AmazonTextract. Note the topic Amazon Resource Name (ARN). Ensure that the topic is in the same Region as the AWS endpoint that you're using.

  4. Create an Amazon SQS standard queue by using the Amazon SQS console. Note the queue ARN.

  5. Subscribe the queue to the topic you created in step 3.

  6. Give permission to the Amazon SNS topic to send messages to the Amazon SQS queue.

  7. Create an IAM service role to give Amazon Textract access to your Amazon SNS topics. Note the Amazon Resource Name (ARN) of the service role. For more information, see Giving Amazon Textract Access to Your Amazon SNS Topic.

  8. Add the following inline policy to the IAM user that you created in step 1:

    { "Version": "2012-10-17", "Statement": [ { "Sid": "MySid", "Effect": "Allow", "Action": "iam:PassRole", "Resource": "arn:Service role ARN from step 7" } ] }

    Give the inline policy a name.

  9. You can now run the examples in Detecting or Analyzing Text in a Multipage Document.

Giving Amazon Textract Access to Your Amazon SNS Topic

Amazon Textract needs permission to send the completion status of an asynchronous operation to your Amazon SNS topic. You use an IAM service role to give Amazon Textract access to the Amazon SNS topic.

When you create the Amazon SNS topic, you must prepend the topic name with AmazonTextract—for example, AmazonTextractMyTopicName.

  1. Sign in to the IAM console (

  2. In the navigation pane, choose Roles.

  3. Choose Create role.

  4. For Select type of trusted entity, choose AWS service.

  5. For Choose the service that will use this role, choose EC2.

  6. Choose Next: Permissions.

  7. For Attach permissions policies, select the check box next to the policy AmazonTextractServiceRole. To display the policy in the list, enter part of the policy name in the Filter policies query filter.

  8. Choose Next: Tags.

  9. You don't need to add tags, so choose Next: Review.

  10. In the Review section, for Role name, enter a name for the role (for example, TextractRole). In Role description, update the description for the role in Role description, and then choose Create role.

  11. Choose the new role to open the role's details page.

  12. In the Summary, copy the Role ARN value and save it.

  13. Choose Trust relationships.

  14. Choose Edit trust relationship, and update the trust policy as follows:

    { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "" }, "Action": "sts:AssumeRole" } ] }
  15. Choose Update Trust Policy.