Overview
Bedrock Chat uses AWS CDK constructs to encapsulate and reuse infrastructure patterns. Each construct represents a logical component of the application.Core Constructs
Auth
Authentication construct using Amazon Cognito. Location:cdk/lib/constructs/auth.ts
Props:
Frontend origin URL for OAuth callbacks
Cognito domain prefix for hosted UI
Identity provider configuration object
Allowed email domains for self-signup (e.g., [“example.com”])
Groups users automatically join after signup
Enable self-service user registration
ID token validity duration
Optional Web ACL ARN to protect the user pool
userPool: Cognito User Pool instanceclient: Cognito User Pool Client
- Admin: Full administrative access
- CreatingBotAllowed: Can create and manage bots
- PublishAllowed: Can publish bot APIs
- Email domain validation via Lambda trigger
- Auto-join groups via post-confirmation trigger
- Support for Google and custom OIDC providers
- Optional WAF protection
Api
Backend REST API construct using API Gateway and Lambda. Location:cdk/lib/constructs/api.ts
Props:
Database construct with DynamoDB tables
Authentication construct for user pool integration
AWS region for Bedrock API calls
S3 bucket for document storage
Step Functions state machine for RAG processing
Enable global inference routing
Enable SnapStart for faster cold starts
Array of model IDs available to users (empty = all models)
Number of warm Lambda instances (0 = disabled)
api: HTTP API Gateway instancehandler: Lambda function handling requests
- Runtime: Python 3.13 with Lambda Web Adapter
- Memory: 1024 MB
- Timeout: 15 minutes
- Architecture: x86_64
- Handler: FastAPI application via
run.sh
- Bedrock API access (
bedrock:*) - DynamoDB table access via assume role
- CodeBuild project start for bot/API creation
- CloudFormation stack operations
- Athena queries for usage analysis
- Cognito user management
- OpenSearch Serverless access
WebSocket
WebSocket API construct for streaming responses. Location:cdk/lib/constructs/websocket.ts
Props:
Database construct for session management
Authentication for WebSocket connections
Region for Bedrock streaming API
S3 bucket for RAG document access
Enable SnapStart for reduced latency
Warm instances for streaming (recommended: 1-2)
webSocketApi: WebSocket API instancehandler: Lambda function for WebSocket eventsapiEndpoint: Full WebSocket endpoint URL
- Runtime: Python 3.13
- Memory: 1024 MB (optimized for streaming)
- Timeout: 15 minutes
- Entry Point:
app/websocket.py
- Message concatenation for inputs >32KB
- Large payload support via S3
- Session management with DynamoDB
- Streaming response from Bedrock
Database
DynamoDB tables for data persistence. Location:cdk/lib/constructs/database.ts
Props:
Enable PITR for conversation table
conversationTable: Conversation storagebotTable: Bot configurationstableAccessRole: IAM role for row-level securitywebsocketSessionTable: WebSocket session dataauditLogTable: User action audit trailcostAllocationTable: Usage cost trackingbotAnalyticsTable: Bot usage metrics
ConversationTable
- PK: UserId
- SK: ConversationId
- GSI: SKIndex (for fetching by conversation ID)
- Features: DynamoDB Streams, PITR (configurable)
BotTable
- PK: UserId
- SK: ItemType
- LSI-1: StarredIndex (IsStarred)
- LSI-2: LastUsedTimeIndex (LastUsedTime)
- GSI-1: BotIdIndex (BotId)
- GSI-2: SharedScopeIndex (SharedScope, SharedStatus)
- GSI-3: ItemTypeIndex (ItemType)
- GSI-4: SyncStatusIndex (SyncStatus)
- Features: DynamoDB Streams, PITR (always enabled)
AuditLogTable
- PK: USER#
- SK: TIMESTAMP##ACTION#
- GSI-1: ActionTypeGSIIndex
- GSI-2: ResourceGSIIndex
- Features: TTL attribute
CostAllocationTable
- PK: PERIOD#
- SK: USER##BOT#
- GSI-1: UserIndex (UserId, PK)
- GSI-2: BotIndex (BotId, PK)
BotAnalyticsTable
- PK: BOT# or BOT##QUERIES
- SK: DATE# or TIMESTAMP#
- Features: TTL attribute
Frontend
CloudFront distribution and S3 hosting for React app. Location:cdk/lib/constructs/frontend.ts
Props:
Web ACL ID for distribution protection
S3 bucket for access logs
Enable IPv6 for CloudFront
Custom domain name (e.g., chat.example.com)
Route53 hosted zone ID for custom domain
ISO country codes for geo-restriction (empty = no restriction)
cloudFrontWebDistribution: CloudFront distributionassetBucket: S3 bucket with website filesgetOrigin(): Returns frontend URL (custom domain or CloudFront)
- Vite build integration via
deploy-time-build - SPA routing with error page redirects
- Optional ACM certificate for custom domains
- Route53 A/AAAA record creation
- Geo-restriction support
Embedding
Step Functions state machine for RAG document processing. Location:cdk/lib/constructs/embedding.ts
Props:
Database for bot sync status tracking
Region for Knowledge Base operations
S3 bucket with source documents
CodeBuild project for custom bot stacks
CodeBuild project for shared KB stacks
Pass-through flag for Knowledge Base replicas
stateMachine: Step Functions state machineremovalHandler: Lambda triggered on bot deletion
- Bootstrap: Load queued bots and shared KBs from DynamoDB
- Shared KB Sync (conditional):
- Acquire distributed lock
- Deploy/update shared KB stack via CodeBuild
- Finalize: Extract KB IDs from CloudFormation outputs
- Ingest: Start data source ingestion jobs
- Release lock
- Custom Bot Processing (parallel):
- Acquire bot-specific lock
- Deploy custom bot stack via CodeBuild
- Finalize: Extract KB/Guardrail IDs
- Ingest: Process file diffs
- Update sync status
- Release lock
UpdateSyncStatusHandler: Updates bot sync status in DynamoDBBootstrapStateMachineHandler: Prepares execution contextFinalizeCustomBotBuildHandler: Extracts custom bot outputsFinalizeSharedKnowledgeBasesBuildHandler: Extracts shared KB outputsSynchronizeDataSourceHandler: Manages ingestion jobsLockHandler: Distributed locking via S3
BotStore
OpenSearch Serverless collection for bot discovery. Location:cdk/lib/constructs/bot-store.ts
Props:
Environment prefix for collection name
DynamoDB bot table to sync from
Conversation table for analytics
Language for text analysis (en, ja, ko, etc.)
Enable standby replicas
openSearchEndpoint: Collection endpoint URLaddDataAccessPolicy(): Method to grant access
en, de, fr, es, ja, ko, zhhans, zhhant, it, nb, th, id, ms
Helper Constructs
UsageAnalysis
Athena and Glue integration for usage analytics. Location:cdk/lib/constructs/usage-analysis.ts
Features:
- DynamoDB export to S3
- Glue Data Catalog tables
- Athena workgroup for queries
- Query result bucket
ApiPublishCodebuild
CodeBuild project for deploying published API stacks. Location:cdk/lib/constructs/api-publish-codebuild.ts
BedrockCustomBotCodebuild
CodeBuild project for deploying custom bot stacks. Location:cdk/lib/constructs/bedrock-custom-bot-codebuild.ts
BedrockSharedKnowledgeBasesCodebuild
CodeBuild project for deploying shared Knowledge Base stacks. Location:cdk/lib/constructs/bedrock-shared-knowledge-bases-codebuild.ts
WebAclForCognito
Regional Web ACL for Cognito User Pool protection. Location:cdk/lib/constructs/webacl-for-cognito.ts
WebAclForPublishedApi
Regional Web ACL for published REST APIs. Location:cdk/lib/constructs/webacl-for-published-api.ts