Skip to main content

Retail Banking Chatbot

A retail banking assistant for AWSome Bank, powered by Amazon Bedrock with RAG-based knowledge retrieval and real-time transaction lookup. Demonstrates the InteractiveAgent construct with Knowledge Base integration, custom tools, and Cognito authentication.

What This Example Demonstrates

  • InteractiveAgent with real-time streaming responses (REST API + Server-Sent Events)
  • Knowledge Base (RAG) using Amazon Bedrock KB with S3 Vectors for banking FAQ retrieval
  • Custom tool (lookup_transactions) querying DynamoDB for customer transaction history
  • Cognito authentication with user sign-up/sign-in
  • React frontend with banking theme hosted on S3 + CloudFront
  • Automated KB provisioning — Knowledge Base, vector store, data source, and ingestion all created in-stack

Architecture

┌─────────────┐     ┌──────────────┐     ┌──────────────────-───┐
│ React UI │────▶│ CloudFront │────▶│ API Gateway (REST) │
│ (S3 hosted)│ │ (CDN) │ │ + Cognito Authorizer│
└─────────────┘ └──────────────┘ └──────────┬────-──────┘


┌────────────────────--------─┐
│ Lambda (InteractiveAgent) │
│ - Strands Agent Framework │
│ - Lambda Web Adapter (SSE) │
└──────┬──────┬────--------───┘
│ │
┌──────────────────┘ └──────────────────┐
▼ ▼
┌─────────────────────┐ ┌──────────────────┐
│ Bedrock Claude LLM │ │ Agent Tools │
│ (reasoning engine) │ ├──────────────────┤
└─────────────────────┘ │ retrieve_from_ │
│ knowledge_base() │
┌───────────────────────-─┐ │ │
│ Bedrock Knowledge Base │◀────│ lookup_ │
│ + S3 Vectors Index │ │ transactions() │
│ + Banking FAQ Docs │ └────────┬─────── ─┘
└───────────────────────-─┘ │

┌──────────────────┐
│ DynamoDB │
│ (Transactions) │
└──────────────────┘

Request Flow

  1. User sends a message through the React frontend
  2. Request is authenticated via Cognito JWT and routed through API Gateway REST API
  3. API Gateway invokes Lambda using response streaming mode (ResponseTransferMode: STREAM) for real-time token-by-token delivery
  4. Lambda runs a FastAPI server via Lambda Web Adapter, streaming SSE events back through API Gateway to the frontend
  5. The Strands agent framework orchestrates the response:
    • For product/policy questions → calls retrieve_from_knowledge_base tool → queries Bedrock KB
    • For transaction queries → calls lookup_transactions tool → queries DynamoDB
    • For combined questions → uses both tools, then synthesizes a response
  6. Response streams back to the frontend via Server-Sent Events (SSE)

Components

ComponentServicePurpose
FrontendS3 + CloudFrontReact chat UI with banking theme
AuthCognito User PoolUser sign-up/sign-in with JWT tokens
APIAPI Gateway RESTChat endpoint with Cognito authorizer and response streaming mode
AgentLambda + StrandsAI agent with tool orchestration, streamed via Lambda Web Adapter
LLMBedrock (Claude)Reasoning, tool selection, response generation
Knowledge BaseBedrock KB + S3 VectorsRAG retrieval for banking FAQs
FAQ StorageS3Source documents for KB ingestion
EmbeddingsTitan Embed Text v2Converts FAQ text to vectors (1024 dimensions)
TransactionsDynamoDBCustomer transaction history (on-demand billing)
SessionsS3Conversation history (24-hour TTL)
ObservabilityCloudWatch + X-RayLogs, metrics, and tracing

Prerequisites

  • AWS CLI configured with appropriate credentials
  • Node.js 18+
  • Python 3.11+
  • CDK bootstrapped: npx cdk bootstrap
  • Amazon Bedrock model access enabled for Claude and Titan Embed Text v2

Deployment

# From the retail-banking-chatbot directory:

# 1. Build the library (from repo root, if not already done)
cd /path/to/repo/root
SKIP_DOCGEN=true npx projen build
npx projen package:js

# 2. Install and deploy infrastructure
cd examples/chatbot/retail-banking-chatbot/infrastructure
npm install
npx cdk deploy --profile <your-profile> --require-approval never --outputs-file ../outputs.json

# 3. Seed transaction data
cd ..
./seed-data.sh

# 4. Configure frontend (copy values from outputs.json)
cat > frontend/.env.production << EOF
REACT_APP_CHAT_API_ENDPOINT=<ChatApiEndpoint from outputs.json>
REACT_APP_USER_POOL_ID=<UserPoolId from outputs.json>
REACT_APP_USER_POOL_CLIENT_ID=<UserPoolClientId from outputs.json>
REACT_APP_REGION=<Region from outputs.json>
EOF

# 5. Build frontend and redeploy
cd frontend && npm install && npm run build && cd ../infrastructure
npx cdk deploy --profile <your-profile> --require-approval never

Sample Prompts

Product & Policy Questions (KB Retrieval)

  • "What types of accounts does AWSome Bank offer?"
  • "What are the overdraft fees? Is there any way to avoid them?"
  • "Do you offer any credit cards with travel rewards?"
  • "What CD rates do you currently offer?"
  • "How do I send money using Zelle?"

Transaction Lookup (DynamoDB Tool)

  • "Can you show me my recent transactions?" → Agent will ask for customer ID
  • "Show me transactions for CUST-001"
  • "Look up transactions for CUST-002"

Combined (Tool + KB)

  • After viewing CUST-001 transactions: "I didn't make that suspicious purchase. What should I do?"
  • After viewing CUST-002 transactions: "What home equity options does AWSome Bank offer?"
  • After viewing CUST-003 transactions: "If I open a 12-month CD with $10,000, what would my return be?"

Available Customers: CUST-001 (Sarah Chen), CUST-002 (Marcus Johnson), CUST-003 (Dorothy Williams)

Sample Data

  • FAQ Documents (sample-docs/): Banking FAQ covering accounts, fees, transfers, cards, digital banking, loans
  • Transaction Data (sample-data/): 34 sample transactions across 3 customer personas

Monitoring

# View agent Lambda logs
aws logs tail /aws/lambda/<AgentFunctionName>-secured --follow --profile <your-profile>

# Check Knowledge Base ingestion status
aws bedrock-agent get-knowledge-base --knowledge-base-id <KnowledgeBaseId> --profile <your-profile>

# Query DynamoDB transactions
aws dynamodb query --table-name <TransactionsTableName> \
--key-condition-expression "customerId = :id" \
--expression-attribute-values '{":id":{"S":"CUST-001"}}' \
--profile <your-profile>

Troubleshooting

IssueCauseFix
Agent not using latest featuresStale library tarballRun npx projen package:js, reinstall, redeploy
Frontend shows old versionCloudFront cacheInvalidate: aws cloudfront create-invalidation --distribution-id <ID> --paths "/*"
Auth error on frontendMissing .env.productionGenerate from outputs.json and rebuild frontend
Empty transaction resultsTable not seededRun ./seed-data.sh

Cleanup

cd infrastructure
npx cdk destroy --profile <your-profile>

This removes all resources including the DynamoDB table, Knowledge Base, S3 buckets, Lambda functions, and CloudFront distribution.