In today’s data-driven landscape, organizations are increasingly leveraging relational databases for their vast data repositories. The integration of generative artificial intelligence (AI) foundation models with these datasets can significantly enhance user experiences. This article delves into the integration of Amazon Aurora MySQL-Compatible Edition with a generative AI model via Amazon Aurora Machine Learning. We will illustrate how to connect Amazon Aurora MySQL with Amazon Bedrock through two practical use cases:
- Enhancing Database Information for Service Improvement – Retrieve additional information using Amazon Bedrock and store it in an Aurora database for immediate access.
- Boosting Productivity – Summarize lengthy text stored in an Aurora database using Amazon Bedrock.
For further insights on utilizing machine learning with Amazon Aurora MySQL, check out this another blog post here.
Solution Overview
Generative AI refers to the technology that can generate new content and ideas, including conversations, narratives, visuals, videos, and music. Foundation models (FMs) are machine learning (ML) models trained on a wide range of generalized and unlabeled data, capable of executing diverse general tasks. Large language models (LLMs), a subset of FMs, focus specifically on language tasks, including summarization, text generation, classification, and information extraction.
Our solution is built upon key components:
- Amazon Aurora: A cloud-based relational database management system (RDBMS) that is compatible with MySQL and PostgreSQL. Aurora provides the performance and availability of high-end commercial databases at a fraction of the cost. Aurora ML allows users to implement various ML algorithms, including predictions, generative AI, and sentiment analysis, all through the familiar SQL programming language. Users don’t need prior ML expertise to utilize Aurora ML, which offers a seamless, secure integration with AWS ML services without necessitating custom integrations or data transfers. Aurora connects with Amazon SageMaker and other AWS services for accessing various ML algorithms.
- Amazon Bedrock: A fully managed service providing access to high-performing FMs from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon, all through a single API. Bedrock simplifies the process of building and scaling generative AI applications while ensuring security, privacy, and responsible AI practices. As a serverless solution, Amazon Bedrock eliminates infrastructure management, allowing users to integrate and deploy generative AI features seamlessly with familiar AWS tools.
The following diagram depicts an example of using ML with Amazon Aurora MySQL.
In the subsequent sections, we will outline how to make real-time calls to Amazon Bedrock using SQL queries from Amazon Aurora MySQL. The primary steps include:
- Creating a new cluster.
- Setting up a database and user.
- Establishing an AWS Identity and Access Management (IAM) role and policy for the Aurora cluster.
- Assigning the IAM role to the Aurora cluster.
- Utilizing Aurora ML by enabling Amazon Bedrock base models.
- Developing functions for accessing Amazon Bedrock.
Prerequisites
This guide assumes a basic familiarity with the AWS Management Console. To implement this solution, ensure that the following resources and services are enabled in your AWS account:
- Amazon Aurora MySQL version 3.06.0 or later is required for integrating with Amazon Bedrock.
- The Aurora MySQL cluster must utilize a custom DB cluster parameter group.
- IAM access is necessary for creating roles and permissions. You should have access to specific FMs in Amazon Bedrock.
- In this article, we will utilize Amazon Titan Text G1 – Express (
amazon.titan-text-express-v1
) and Anthropic Claude 3 Haiku (anthropic.claude-3-haiku-20240307-v1:0
). - The ML services must operate within the same AWS Region as your Aurora MySQL cluster.
- The network configuration of your Aurora MySQL cluster must permit outbound connections to Amazon Bedrock endpoints.
Creating an Aurora MySQL Cluster
The first step is to establish an Aurora MySQL cluster. For detailed instructions, refer to the guide on Creating and connecting to an Aurora MySQL DB cluster. Below are some specific configuration options utilized in this example:
- In the Aurora console, create a new cluster in a Region that supports Amazon Bedrock (e.g., us-east-1).
- For Engine options, select Aurora (MySQL Compatible) and for Engine version, use Aurora MySQL 3.06.0 to enable Amazon Bedrock integration.
- For Configuration options, choose either Aurora Standard or Aurora I/O Optimized.
- Select your desired DB instance class.
- Since you will need to modify the parameter group later for Amazon Bedrock, apply a custom DB cluster parameter group at this stage.
- After provisioning the cluster, execute a series of SQL commands to prepare your cluster for integration with Amazon Bedrock.
Log in to your Aurora cluster as a user with the rds_superuser_role
privilege (such as the master user) via MySQL Command-Line Client, and run the following commands. Ensure that the AWS_BEDROCK_ACCESS
database role is granted to the user to utilize Amazon Bedrock ML functions.
mysql> create database bedrockdb; /*** Sample Database ***/
Query OK, 1 row affected (0.03 sec)
mysql> create user `bedrock_user`@`%` identified by 'password'; /*** Sample User ***/
Query OK, 0 rows affected (0.30 sec)
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER, INDEX, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON bedrockdb.* TO `bedrock_user`@`%`;
Query OK, 0 rows affected (0.05 sec)
mysql> GRANT AWS_BEDROCK_ACCESS TO `bedrock_user`@`%`;
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW GRANTS FOR `bedrock_user`@`%`G
*************************** 1. row ***************************
Grants for bedrock_user@%: GRANT USAGE ON *.* TO `bedrock_user`@`%`
*************************** 2. row ***************************
Grants for bedrock_user@%: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, EXECUTE, CREATE ROUTINE, ALTER ROUTINE ON `bedrockdb`.* TO `bedrock_user`@`%`
*************************** 3. row ***************************
Grants for bedrock_user@%: GRANT `AWS_BEDROCK_ACCESS`@`%` TO `bedrock_user`@`%`
Your database user is now configured to integrate with Amazon Bedrock. Next, you need to create an IAM role that allows the Aurora MySQL DB cluster to access Amazon Bedrock.
Creating an IAM Role and Policy for the Aurora Cluster
To enable Aurora ML to operate with Amazon Bedrock, begin by creating an IAM policy that permits the Aurora cluster to communicate with Amazon Bedrock models. Follow these steps:
- In the IAM console, select Policies from the navigation pane.
- Click on Create policy.
- On the Specify permissions page, select Bedrock as the service.
- In the policy editor, expand Bedrock and…
Leave a Reply