Create and query an index

with Amazon Kendra

In this tutorial, you learn how to use Amazon Kendra create a new index and query the index for results.  

Amazon Kendra is a highly accurate and easy to use enterprise search service that’s powered by machine learning. Amazon Kendra delivers powerful search capabilities to your websites and applications, so your end users can quickly find the information they need within the vast amount of content spread across your company.

Amazon Kendra lets you ask natural language questions in addition to simple keywords and get the answers you’re looking for, whether that is a precise answer, an FAQ response, or an entire document. Amazon Kendra also lets you easily add content from Amazon S3, Amazon RDS, Microsoft SharePoint Online, ServiceNow, and Salesforce into a centralized location.

In this tutorial, you learn how to:

  1. Set up a new index in Amazon Kendra
  2. Set up an Amazon S3 bucket as a data source and ingest data using an Amazon Kendra connector
  3. Set up an FAQ data source
  4. Query the index using the Console search

For this tutorial, you use Amazon.com help documents in HTML format as discovered by the Amazon Kendra data source connector.

About this Tutorial
Time 1 hour                                          
Cost Less than $1
Use Case Machine Learning
Products Amazon Kendra
Audience Developer
Level Beginner
Last Updated September 11, 2020

Step 1. Create an AWS Account

The cost of this tutorial is less than $1.

Already have an account? Sign-in

Step 2. Set up the Amazon Kendra index

Complete the following steps to set up the Amazon Kendra index. An index can contain documents that are indexed from a data source, documents that are added directly to the index, and FAQs. Once the index is active you can index your documents using the operation or using one of the supported data sources.

Note: For more information, see Creating an index in the Amazon Kendra documentation.


a. Sign in to the Amazon Kendra console, and in the top right corner, verify your AWS Region is set to N. Virginia. Then, choose Create an index.


b. On the Index details page, fill the following fields and choose Next.

  • Index name: hands-on-tutorial
  • Description: Amazon Kendra tutorial.
  • IAM role: Create a new role
  • Role name: AmazonKendra-us-east-1-hands-on-tutorial

c. On the Provisioning editions page, choose Developer edition and then choose Create.
The index creation process takes an average of 15 minutes, but may take up to 30 minutes.

Step 3. Update the IAM role

When you create an index, data source, or an FAQ, Amazon Kendra needs access to the AWS resources required to create the Amazon Kendra resource. While the index is being created, you can update the IAM role to allow it to read from Amazon S3. In a production environment, this step is where you can lock down access to only read specific buckets or files/objects.

Complete the following steps to update the IAM role to allow Amazon S3 access.

Note: For more information, see IAM access roles for Amazon Kendra in the Amazon Kendra documentation.


a. Open the IAM console and in the left navigation pane, choose Roles. In the search box, type hands-on-tutorial. Select and choose the AmazonKendra-us-east-1-hands-on-tutorial role.

b. On the Summary page, choose Attach policies.

c. On the Attach permissions page, in the search box, type S3, and select the AmazonS3ReadOnlyAccess policy. Choose Attach policy.
On the Summary page, you should see two policies attached to the IAM role.
d. Return to the Amazon Kendra console and wait for the status of your index from Step 2 to change from Creating to Active before continuing to the next step.

Step 4. Configure an S3 connector to the data source

A data source is a location, such as an Amazon Simple Storage Service (Amazon S3) bucket, where you store the documents for indexing. Data sources can be automatically synchronized with an Amazon Kendra index so that new, updated, or deleted documents in the source repositories are included in searches. Connectors maintain document access rights and can be scheduled to automatically sync your index with your data source, so you're always securely searching through the most up to date content.

Complete the following steps to add a connector to the Amazon S3 bucket containing the Amazon.com help documents sample as a data source.

Note: For more information, see Data sources in the Amazon Kendra documentation.


a. In the Indexes list, choose your hands-on-tutorial.

b. In the left navigation pane, under Data management, choose Data sources. Under connector type, in the Amazon S3 box, choose Add connector.

c. On the Define attributes page, for Data source name, type Amazon-com-help-pages and choose Next.

d. On the Configure settings page, for Data source location, type  s3://serverless-analytics. For IAM role, choose the AmazonKendra-us-east-1-hands-on-tutorial role you created earlier. Then, expand Additional configuration.

e. In the Additional configuration section, for Include patterns, type amazon-help/documents/ and choose Add.

f. In the Set sync run schedule section, for Frequency, choose Run on demand and then choose Next.

g. Review the configuration details and then choose Create.

h. On the Data source details page, choose Sync now.
The S3 connector starts crawling and indexing the content it has permission to access through the assigned IAM role.

When the sync is completed, the Last sync status of the data source changes to Succeeded.

Step 5. Add an FAQ

For this step, you upload an FAQ to provide Kendra with direct answers to commonly asked questions. Amazon Kendra finds the closest question to the search query and returns the corresponding answer.

Complete the following steps to add an FAQ using the sample amazon-help-faqs.

Note: For more information, see Amazon Kendra Features.


a. In the left navigation pane of the Amazon Kendra console, choose FAQs, then choose Add FAQ.

b. On the Add FAQ page, fill the following fields and choose Add:
  • FAQ name: amazon-help-faqs
  • S3: s3://serverless-analytics/amazon-help/faqs/kendrapost.csv
  • IAM role: AmazonKendra-us-east-1-hands-on-tutorial

You should see the new FAQ and a message, You successfully created the following FAQ:’amazon-help-faqs’.

Step 6. Query the index

Now you can use the text search console to query your newly created index. This is just one of many ways you can query your index. When you search your index, Amazon Kendra uses all of the information that you provided to return the most accurate answer and relevant documents to your search query.  

Complete the following steps to query your newly created index.

Note: For more information, see Searching indexes in the Amazon Kendra documentation.


a. In the left navigation pane of the Amazon Kendra console, choose Search console. In the search box, type your first query: What is Amazon music unlimited?
 
At the top of the results, you can see an Amazon Kendra returned result.
b. Next, type another query: shipping rates to Canada
 
You can see another result returned by Amazon Kendra.

c. Type a more direct query: How do I sign up for the Amazon Prime free Trial?
 
In the results, you can see the Amazon Kendra recommended answer it pulled from the indexed documents along with a new answer from the FAQ data source.

Step 7. Clean up

In this step, you terminate the resources you used in this lab.

Important: Terminating resources that are not actively being used reduces costs and is a best practice. Not terminating your resources will result in charges to your account.


Delete the index:

  1. Open the Amazon Kendra Console.
  2. In the left navigation pane, choose Indexes.
  3. Choose the hands-on-tutorial index and then choose Actions, Delete.
  4. Type Delete to confirm.

Delete the IAM role and policy:

  1. Open the IAM Console.
  2. In the left navigation pane, choose Roles.
  3. In the search box, type hands-on-tutorial.
  4. Select the AmazonKendra-us-east-1-hands-on-tutorial role and then choose Delete role.
  5. Choose Yes, delete
  6. In the left navigation pane, choose Policies.
  7. In the search box, type hands-on-tutorial.
  8. Select the AmazonKendra-us-east-1-hands-on-tutorial policy and then choose Policy actions, Delete.
  9. Choose Delete.

Congratulations

You created and queried an index with Amazon Kendra.

Was this tutorial helpful?

Learn more

Learn more about Amazon Kendra by reading the Amazon Kendra Developer Guide.

Read more about Amazon Kendra features

See the Amazon Kendra Features page for more information.

Explore other machine learning services tutorials