How build-on-aws/elevating-customer-support-with-rag-langchain-agent-bedrock-dynamodb-and-kendra works
Project type and purpose
• This is a serverless, full-stack “customer support bot” app built with AWS CDK (Python).
• It uses AWS Lambda for compute, API Gateway as the webhook entry point, Amazon Bedrock (LLM) + LangChain for natural-language processing, Amazon Kendra for Q&A over a PDF knowledge base, DynamoDB for session and passenger data, Amazon Transcribe for voice notes, and optionally an S3+CloudFront site for static hosting.
High-level file-structure analysis
• Top level: project metadata (README, LICENSE, CODE_OF_CONDUCT, etc.) and a “customer-support-bot” subfolder which contains:
• CDK app (app.py, cdk.json)
• Two CDK stacks under customer_support_bot/:
– customer_support_bot_stack.py (main infra)
– application_insights_stack.py (observability)
• Constructs for Kendra (kendra_constructs/), databases (databases/), S3+CloudFront (s3_cloudfront/).
• A lambdas/ folder with per-Lambda subfolders under code/, plus helper modules (datasource.py, project_lambdas.py).
• A layers/ folder bundling common Python utilities and third-party libs.
• A sample airline dataset and PDF Q&A base under airline-dataset/ and airline-qa-base/.
Core architecture components
a. External interfaces
• WhatsApp Business (incoming messages + webhooks)
• Facebook/Meta webhook API
• Developer’s AWS CDK CLI (deploys all infra)
b. Ingress/API Layer
• API Gateway (HTTP endpoint) receives WhatsApp webhook calls
c. Compute (AWS Lambda functions)
• whatsapp_in: parses webhook payloads, persists raw events
• langchain_agent_text: orchestrates LLM calls (Bedrock), calls DynamoDB-based memory, invokes Kendra search, builds the response
• audio_job_transcriptor, process_stream, transcriber_done: handle audio streams via Amazon Transcribe
• query_dynamodb_passanger: lookup passenger record by reservation ID
• dynamodb_put_item: write session state or passenger data
• whatsapp_out: posts responses back to WhatsApp API
• data_source_creator: (one-off) populates/upserts the Kendra data source for PDF ingestion
d. Data layer
• Amazon DynamoDB:
• session_table (conversation history)
• session_active_table (session timeouts)
• Passenger_ID (sample passenger data)
• Amazon Kendra Index + DataSource (PDFs under airline-qa-base)
e. AI/ML services
• Amazon Bedrock LLM (text generation)
• Amazon Transcribe (speech-to-text)
f. Configuration and secrets
• AWS Secrets Manager (WhatsApp credentials)
• CDK Parameter overrides (e.g. DISPLAY_PHONE_NUMBER)
Data-flow and relationships
1. User sends text or voice on WhatsApp
2. Meta/WhatsApp webhook → API Gateway → whatsapp_in Lambda
3. For voice: whatsapp_in uploads media to S3, triggers audio_job_transcriptor → Transcribe → transcriber_done → pushes transcript back into the flow
4. langchain_agent_text Lambda:
• retrieves session history from DynamoDB
• calls Amazon Kendra for Q&A lookup over PDFs
• calls Amazon Bedrock (via LangChain) with prompt + memory + Kendra results
• writes updated memory to DynamoDB
5. Query passenger info via query_dynamodb_passanger if requested
6. Formulate final response JSON → whatsapp_out Lambda → Meta API → user
Architectural patterns and design principles
• Serverless, event-driven (Lambda + triggers)
• Single-responsibility Lambdas (each function does one job)
• Infrastructure as Code (AWS CDK) following modular constructs
• Layered Python code (common utilities in Lambda Layers)
• Data-driven AI orchestration (DynamoDB memory + Kendra context + LLM)
• Secure secret management (Secrets Manager for WhatsApp tokens)