Skip to content

Commit 6a64e60

Browse files
aurbacUriel Ramirez
andauthored
CDK Deployment and DB Read-Only User (#179)
* Cognito Authentication Added * Cognito Authentication Added * Cognito Authentication Added * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * AgentCore Enhanced Deployment Option * CDK Deployment and DB Read-Only User * CDK Deployment and DB Read-Only User --------- Co-authored-by: Uriel Ramirez <beralfon@amazon.com>
1 parent 215f117 commit 6a64e60

File tree

26 files changed

+1039
-1741
lines changed

26 files changed

+1039
-1741
lines changed

examples/agents_ux/video_games_sales_assistant_with_amazon_bedrock_agents/README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
> [!IMPORTANT]
99
> **🚀 Ready-to-Deploy Agent Web Application**: Use this reference solution to build other agent-powered web applications across different industries. Extend the agent capabilities by adding custom tools for specific industry workflows and adapt it to various business domains.
1010
11-
This solution provides a Generative AI application reference that allows users to interact with data through a natural language interface. The solution connects **[Amazon Bedrock Agents](https://aws.amazon.com/bedrock/agents/)** to a PostgreSQL database, providing data analysis capabilities through a Web Application interface.
11+
This solution provides a Generative AI application reference that allows users to interact with data through a natural language interface. The solution uses **[Amazon Bedrock Agents](https://aws.amazon.com/bedrock/agents/)** connected to a PostgreSQL database for data analysis capabilities, deployed with **[AWS CDK](https://docs.aws.amazon.com/cdk/v2/guide/home.html)** for back-end infrastructure and **[AWS Amplify](https://docs.amplify.aws/)** for the front-end web application.
1212

1313
<div align="center">
1414
<img src="./images/data-analyst-assistant-amazon-bedrock-agents.gif" alt="Conversational Data Analyst Assistant Solution with Amazon Bedrock Agents">
@@ -39,24 +39,28 @@ The following architecture diagram illustrates a reference solution for a genera
3939

4040
> [!IMPORTANT]
4141
> This sample application is meant for demo purposes and is not production ready. Please make sure to validate the code with your organizations security best practices.
42-
>
43-
> Cost Alert: This solution will cost approximately $180 USD per month, mainly for Aurora Serverless and RDS Proxy, plus the usage of on-demand services like Amazon Bedrock and Lambda functions. Please ensure you understand these costs before deployment.
4442
45-
The solution deploys the following AWS services:
43+
### CDK Infrastructure Deployment
44+
45+
The AWS CDK stack deploys and configures the following managed services:
4646

47-
- **Amazon Bedrock Agent**: Powers the ***Data Analyst Assistant*** that answers questions by generating SQL queries using Claude 3.5 Haiku
47+
- **Amazon Bedrock Agent**: Powers the ***Data Analyst Assistant*** that answers questions by generating SQL queries using Claude Haiku 4.5
4848
- **AWS Lambda**: Processes agent requests through various tools including:
49-
- /runSQLQuery: Executes queries against the database
49+
- /runSQLQuery: Executes queries against the database via the RDS Data API
5050
- /getCurrentDate: Retrieves the current date
5151
- /getTablesInformation: Provides database tables information for agent context
52-
- **Aurora Serverless PostgreSQL**: Stores the video game sales data
52+
- **Amazon Aurora Serverless v2 PostgreSQL**: Stores the video game sales data with RDS Data API integration
5353
- **Amazon DynamoDB**: Tracks questions and query results
54-
- **AWS Secrets Manager**: Securely stores database credentials
55-
- **Amazon VPC**: Provides network isolation for the database
54+
- **AWS Secrets Manager**: Securely stores database credentials (admin and read-only user)
55+
- **Amazon VPC**: Provides network isolation for the database with public and private subnets
56+
- **Amazon S3**: Import bucket for loading data into Aurora PostgreSQL
57+
58+
### Amplify Deployment for the Front-End Application
59+
5660
- **React Web Application**: Delivers the user interface for the assistant
5761
- Uses Amazon Cognito for user authentication and permissions management
5862
- The application invokes the Amazon Bedrock Agent for interacting with the assistant
59-
- For chart generation, the application directly invokes the Claude 3.7 Sonnet model
63+
- For chart generation, the application directly invokes the Claude Haiku 4.5 model
6064

6165
> [!NOTE]
6266
> The React Web Application uses Amazon Cognito for user authentication and permissions management, providing secure access to Amazon Bedrock and Amazon DynamoDB services through authenticated user roles.
@@ -70,17 +74,17 @@ The solution deploys the following AWS services:
7074
The **user interaction workflow** operates as follows:
7175

7276
- The web application sends user business questions to the Amazon Bedrock Agent
73-
- The agent (powered by Claude 3.5 Haiku) processes natural language and determines when to execute database queries
74-
- Lambda functions execute SQL queries against the Aurora PostgreSQL database and send the results back to the agent, which formulates an answer to the question
77+
- The agent (powered by Claude Haiku 4.5) processes natural language and determines when to execute database queries
78+
- Lambda functions execute SQL queries against the Aurora PostgreSQL database via the RDS Data API and send the results back to the agent, which formulates an answer to the question
7579
- After the agent's response is received by the web application, the raw data query results are retrieved from the DynamoDB table to display both the answer and the corresponding records
76-
- For chart generation, the application invokes a model (powered by Claude 3.7 Sonnet) to analyze the agent's answer and raw data query results to generate the necessary data to render an appropriate chart visualization
80+
- For chart generation, the application invokes a model (powered by Claude Haiku 4.5) to analyze the agent's answer and raw data query results to generate the necessary data to render an appropriate chart visualization
7781

7882
## Deployment Instructions
7983

8084
The deployment consists of two main steps:
8185

82-
1. **Generative AI Application** - [Data Source and Amazon Bedrock Agent Deployment with AWS SAM](./sam-bedrock-video-games-sales-assistant/)
83-
2. **Front-End Implementation** - [Integrating Amazon Bedrock Agent with a Ready-to-Use Data Analyst Assistant Application](./amplify-video-games-sales-assistant-bedrock-agent/)
86+
1. **Generative AI Application** - [Data Source and Amazon Bedrock Agent Deployment with AWS CDK](./cdk-video-games-sales-assistant-bedrock-agent/)
87+
2. **Front-End Implementation** - [Deploying a Conversational Data Analyst Assistant Solution with Amazon Bedrock Agents](./amplify-video-games-sales-assistant-bedrock-agent/)
8488

8589
> [!NOTE]
8690
> *It is recommended to use the Oregon (us-west-2) or N. Virginia (us-east-1) regions to deploy the application.*
@@ -118,4 +122,4 @@ The following images showcase a conversational experience analysis that includes
118122

119123
## License
120124

121-
This project is licensed under the Apache-2.0 License.
125+
This project is licensed under the Apache-2.0 License.

examples/agents_ux/video_games_sales_assistant_with_amazon_bedrock_agents/amplify-video-games-sales-assistant-bedrock-agent/README.md

Lines changed: 70 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
# Front-End Implementation - Integrating Amazon Bedrock Agent with a Ready-to-Use Data Analyst Assistant Application
22

3-
This tutorial guides you through setting up a React Web application that integrates with your Amazon Bedrock Agent, creating a Data Analyst Assistant for Video Game Sales.
3+
This tutorial guides you through setting up a React Web application using **[AWS Amplify](https://docs.amplify.aws/)** that integrates with your **[Amazon Bedrock Agent](https://aws.amazon.com/bedrock/agents/)** deployment, creating a Data Analyst Assistant for Video Game Sales.
4+
5+
> [!NOTE]
6+
> **Working Directory**: Make sure you are in the `amplify-video-games-sales-assistant-bedrock-agent/` folder before starting this tutorial. All commands in this guide should be executed from this directory.
47
58
## Overview
69

7-
By the end of this tutorial, you'll have a fully functional Generative AI web application that allows users to interact with a Data Analyst Assistant interface.
10+
By the end of this tutorial, you'll have a fully functional Generative AI web application that allows users to interact with a Data Analyst Assistant interface powered by Amazon Bedrock Agents.
811

912
The application consists of two main components:
1013

1114
- **React Web Application**: Provides the user interface and handles user interactions
1215
- **Amazon Bedrock Integration:**:
1316
- Uses your Bedrock Agent for data analysis and natural language processing
1417
- The application invokes the Amazon Bedrock Agent for interacting with the assistant
15-
- Directly invokes Claude 3.7 Sonnet model for chart generation and visualization
18+
- Directly invokes Claude Haiku 4.5 model for chart generation and visualization
1619

1720
> [!IMPORTANT]
1821
> This sample application is for demonstration purposes only and is not production-ready. Please validate the code against your organization's security best practices.
@@ -22,10 +25,6 @@ The application consists of two main components:
2225
Before you begin, ensure you have:
2326

2427
- [Node.js version 18+](https://nodejs.org/en/download/package-manager)
25-
- React Scripts installed:
26-
``` bash
27-
npm install react-scripts
28-
```
2928

3029
## Set Up the Front-End Application
3130

@@ -39,7 +38,7 @@ npm install
3938

4039
### Install Amplify CLI
4140

42-
Install the Amplify CLI globally:
41+
Install the **[AWS Amplify](https://docs.amplify.aws/)** CLI globally:
4342

4443
``` bash
4544
npm install -g @aws-amplify/cli
@@ -53,6 +52,9 @@ Initialize the Amplify project:
5352
amplify init
5453
```
5554

55+
- Do you want to continue with Amplify Gen 1? **`yes`**
56+
- Why would you like to use Amplify Gen 1? **`Prefer not to answer`**
57+
5658
Use the following configuration:
5759

5860
- ? Enter a name for the project: **`daabedrockagent`**
@@ -98,12 +100,51 @@ amplify push
98100
> [!NOTE]
99101
> This creates a Cognito User Pool and Identity Pool in your AWS account for user authentication. AWS credentials for the Front-End Application are automatically managed through Cognito.
100102
103+
## Get CDK Output Values
104+
105+
Get the required values from your CDK project outputs. These values are needed for configuring AuthRole permissions and environment variables:
106+
107+
``` bash
108+
# Set the stack name environment variable
109+
export STACK_NAME=CdkVideoGamesSalesAssistantBedrockAgentStack
110+
111+
# Get the values from CDK outputs
112+
export AGENT_ARN=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey=='AgentARN'].OutputValue" --output text)
113+
export AGENT_ID=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey=='AgentId'].OutputValue" --output text)
114+
export QUESTION_ANSWERS_TABLE_NAME=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey=='QuestionAnswersTableName'].OutputValue" --output text)
115+
export QUESTION_ANSWERS_TABLE_ARN=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey=='QuestionAnswersTableArn'].OutputValue" --output text)
116+
export ACCOUNT_ID=$(aws cloudformation describe-stacks --stack-name "$STACK_NAME" --query "Stacks[0].Outputs[?OutputKey=='AccountId'].OutputValue" --output text)
117+
118+
cat << EOF
119+
# Agent Resources
120+
AGENT_ARN: ${AGENT_ARN}
121+
AGENT_ID: ${AGENT_ID}
122+
ACCOUNT_ID: ${ACCOUNT_ID}
123+
124+
# DynamoDB Resources
125+
QUESTION_ANSWERS_TABLE_NAME: ${QUESTION_ANSWERS_TABLE_NAME}
126+
QUESTION_ANSWERS_TABLE_ARN: ${QUESTION_ANSWERS_TABLE_ARN}
127+
EOF
128+
```
129+
101130
## Configure AuthRole Permissions
102131

103132
After authentication deployment, you need to grant your authenticated users permission to access AWS services.
104133

105-
1. **Find your AuthRole**: Go to AWS Console → IAM → Roles → Search for amplify-daabedrockagent-dev-*-authRole
106-
2. **Add this policy** (replace the placeholder values with your actual values from SAM outputs):
134+
1. **Find your AuthRole**: Go to AWS Console → IAM → Roles → Search for `amplify-daabedrockagent-dev-*-authRole`
135+
136+
2. **Add an inline policy**: Click on the role → **Add permissions****Create inline policy** → Select **JSON** tab
137+
138+
3. **Copy the policy below** and replace the following placeholders with your actual values:
139+
140+
| Placeholder | Replace With | Example |
141+
|-------------|--------------|---------|
142+
| `<account_id>` | Your AWS Account ID (12-digit number) | `123456789012` |
143+
| `<agent_arn>` | `AGENT_ARN` from CDK outputs above | `arn:aws:bedrock:us-east-1:123456789012:agent/XXXXXXXXXX` |
144+
| `<agent_id>` | `AGENT_ID` from CDK outputs above | `XXXXXXXXXX` |
145+
| `<question_answers_table_arn>` | `QUESTION_ANSWERS_TABLE_ARN` from CDK outputs above | `arn:aws:dynamodb:us-east-1:123456789012:table/QuestionAnswers-xxx` |
146+
147+
**Policy to copy (replace placeholders):**
107148

108149
``` json
109150
{
@@ -127,10 +168,12 @@ After authentication deployment, you need to grant your authenticated users perm
127168
"bedrock:InvokeModel"
128169
],
129170
"Resource": [
130-
"arn:aws:bedrock:*:<account_id>:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0",
131-
"arn:aws:bedrock:us-east-2::foundation-model/anthropic.claude-3-7-sonnet-20250219-v1:0",
132-
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-7-sonnet-20250219-v1:0",
133-
"arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-7-sonnet-20250219-v1:0"
171+
"arn:aws:bedrock:us-east-1:<account_id>:inference-profile/us.anthropic.claude-haiku-4-5-20251001-v1:0",
172+
"arn:aws:bedrock:us-east-2:<account_id>:inference-profile/us.anthropic.claude-haiku-4-5-20251001-v1:0",
173+
"arn:aws:bedrock:us-west-2:<account_id>:inference-profile/us.anthropic.claude-haiku-4-5-20251001-v1:0",
174+
"arn:aws:bedrock:us-east-2::foundation-model/anthropic.claude-haiku-4-5-20251001-v1:0",
175+
"arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-haiku-4-5-20251001-v1:0",
176+
"arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-haiku-4-5-20251001-v1:0"
134177
]
135178
},
136179
{
@@ -145,6 +188,8 @@ After authentication deployment, you need to grant your authenticated users perm
145188
}
146189
```
147190

191+
4. **Save the policy** with a name like `DataAnalystAssistantPermissions`
192+
148193
## Configure Environment Variables
149194

150195
Rename the file **src/sample.env.js** to **src/env.js**:
@@ -153,15 +198,17 @@ Rename the file **src/sample.env.js** to **src/env.js**:
153198
mv src/sample.env.js src/env.js
154199
```
155200

156-
In you **src/env.js** update the following environment variables
201+
In your **src/env.js** update the following environment variables using the CDK output values from above:
157202

158-
- AWS Region:
159-
- **AWS_REGION**
203+
- **AWS_REGION**: Your AWS region (e.g., `us-east-1`)
204+
- **AGENT_ID**: Your Bedrock Agent ID from CDK outputs
205+
- **AGENT_ALIAS_ID**: Your Bedrock Agent Alias ID (create an alias in the Bedrock console)
206+
- **QUESTION_ANSWERS_TABLE_NAME**: Use the value from the CDK outputs above
160207

161-
- Agent and DynamoDB table name information that you can find in the CloudFormation Outputs from the SAM project:
162-
- **AGENT_ID**
163-
- **AGENT_ALIAS_ID**
164-
- **QUESTION_ANSWERS_TABLE_NAME**
208+
Also, you can update the general application description:
209+
- **APP_NAME**: "Data Analyst Assistant"
210+
- **APP_SUBJECT**: "Video Games Sales"
211+
- **WELCOME_MESSAGE**: Your custom welcome message
165212

166213
## Test Your Data Analyst Assistant
167214

@@ -230,7 +277,7 @@ Give me a short summary and conclusion of our conversation.
230277

231278
## Deploy your Application with Amplify Hosting
232279

233-
To deploy your application yu can use AWS Amplify Hosting:
280+
To deploy your application you can use AWS Amplify Hosting:
234281

235282
### Add Hosting
236283

@@ -284,4 +331,4 @@ Congratulations! Your Data Analyst Assistant can provide you with the following
284331

285332
## License
286333

287-
This project is licensed under the Apache-2.0 License.
334+
This project is licensed under the Apache-2.0 License.

examples/agents_ux/video_games_sales_assistant_with_amazon_bedrock_agents/amplify-video-games-sales-assistant-bedrock-agent/src/sample.env.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const WELCOME_MESSAGE = "I'm your Video Games Sales Data Analyst, crunching data
1818
// ================================
1919

2020
const MAX_LENGTH_INPUT_SEARCH = 140;
21-
const MODEL_ID_FOR_CHART = "us.anthropic.claude-3-7-sonnet-20250219-v1:0";
21+
const MODEL_ID_FOR_CHART = "us.anthropic.claude-haiku-4-5-20251001-v1:0";
2222

2323
const CHART_PROMPT =
2424
'\n\
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.js
2+
!jest.config.js
3+
*.d.ts
4+
node_modules
5+
.DS_Store
6+
package-lock.json
7+
8+
# CDK asset staging directory
9+
.cdk.staging
10+
cdk.out
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.ts
2+
!*.d.ts
3+
4+
# CDK asset staging directory
5+
.cdk.staging
6+
cdk.out

0 commit comments

Comments
 (0)