logo
Menu

Amazon Q Business-Connecting Amazon RDS (MySQL)

Building an generative AI based app to query Amazon RDS (MySQL) with Amazon Q Business and make them conversational without writing any complex code.

Nitin Eusebius
Amazon Employee
Published Jun 30, 2024
Last Modified Jul 1, 2024
In this post, I want to share how easy it is to connect data sources to Amazon Q Business. This integration allows us to interact with Amazon RDS (MySQL) using natural language, utilizing AWS generative AI. With Amazon Q Business, you can build an interactive chat application for your organization’s end users, using a combination of your enterprise data and large language model knowledge, or enterprise data only.
Amazon Q Business offers multiple data source connectors that can connect to your data sources and help you create your generative AI solution with minimal configuration. A data source connector is a mechanism for integrating and synchronizing data from multiple repositories into one container index. For more information of all offered connectors, please visit the documentation page.
When it comes to data sources and in this case RDS MySQL, we have the following
Supports crawling :
  • Table data in a single database
  • View data in a single database
Document definition :
  • Each row in a table and view is considered a single document.
Now, lets dive right in.

Prerequisites

Before we get started, we need to have the following prerequisites in place
  1. A valid working AWS account with required resource access
  2. RDS MySQL set up , for more information please visit documentation
  3. Amazon Q Business set up, please visit getting started guide
    1. Complete the steps to create your Amazon Q application.
    2. Complete the steps for selecting an Amazon Q retriever.
  4. AWS Cloud 9 environment to help running our sample data and scripts for MySQL. Please visit getting started guide
Note : For the demo, I have put RDS MySQL in a VPC within private subnets only with NAT associated with it. We will create the instance of Amazon Q Business and AWS Cloud 9 within same vpc and subnet.

Sample code and data for setting up RDS MySQL sample data

Once we have our RDS MySQL and AWS cloud 9 set up, we will use python mysql connector to run these in our cloud9 environment.
Note : You can also do below set up with any MySQL compatible clients.
Please replace with your credentials , hostname and database name.
For the purpose of demo, I will be using public available sample data about few movies, actors and reviews. Run the following scripts
Once completed, you can verify your data running the following
with this in place, lets move to setting up Amazon Q for business connector for RDS MySQL

Connecting Amazon RDS (MySQL) to Amazon Q Business

Amazon RDS (MySQL) (Amazon Relational Database Service) is a web service that makes it easier to set up, operate, and scale a relational database in the AWS Cloud. You can connect your Amazon RDS (MySQL) instance to Amazon Q Business – using either the AWS Management Console, CLI, or the CreateDataSource API – and create an Amazon Q web experience.
I will be following this guide to set up the connector using the console. We need to make sure we follow our prerequisites as noted before.
RDS MySQL connector
RDS MySQL connector data source selection
Once you followed rest of the steps in the guide, lets take a look on sync scopes we will add. You will need to add 2-3 different data sources per your needs. For this demo, we will add two.
Data source sync scope 1 - Movie details
SELECT movie_id, title, CONCAT('movie_id:', m.movie_id, ' title:', m.title, ' release_date:', m.release_date, ' genre:', m.genre, ' director:', m.director, ' plot:', m.plot, ' main_actor_id:', m.main_actor_id, ' actor_details: actor_id:', a.actor_id, ' first_name:', a.first_name, ' last_name:', a.last_name, ' bio:', a.bio) AS movie_details FROM movies m JOIN actors a ON m.main_actor_id = a.actor_id
Add movie_id as primary key column, title as title column and movie_details as Body column.
Movie details sync scope
RDS MySQL connector sync scope 1
Data source sync scope 2 - Movie reviews
SELECT review_id, movie_name, CONCAT('review_id:', c.review_id, ' movie_name:', c.movie_name, ' review:', c.review) AS movie_review_details FROM movie_reviews_all c
Add review_id as primary key column, movie_name as title column and movie_review_details as Body column.
Movie review sync scope
RDS MySQL connector sync scope 2
Leave everything else as default. With this set up done, lets sync each of the above data source and wait for it to complete. If there are any sync errors, you will see on this console and will be able to look into the Amazon CloudWatch under details column.
sync
Amazon Q Business sync

Amazon Q Business Conversations.

With everything in place lets ask few queries.

Conclusion

I was really impressed by how easily I could set up this integration using RDS MySQL connector and Amazon Q for business. Now we can easily and securely query our existing data easily and get quick insights with minimal set up. In this blog post, I showed you how to get started with Amazon Q for Business and RDS MySQL connector and then ask some natural query questions to the system. We also saw how Amazon Q for business can provide citations of the data it brings from the data sources.
Happy Building !
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments