Simple WhatsApp bot infrastructure on AWS Lambda using CDK.
uv syncTo start developing locally:
docker compose upCreate the tables:
EVENTS_TABLEMESSAGES_TABLE
make tablesCreate the RAG bucket:
make bucketRun the app:
uv run uvicorn handler:app --reloadIf you don't want to read:
docker compose up --buildDeploy:
npx aws-cdk deploy --app 'uv run infra.py' --verbose
# or
make deployDestroy:
npx aws-cdk destroy --app 'uv run infra.py' --verbose
# or
make destroyRedeploy:
npx aws-cdk destroy --app 'uv run infra.py' --verbose
# or
make resetArchitecture diagram of the infrastructure:
graph TD
User --[send message]--> WhatsApp
WhatsApp --[wbehooks]--> ApiGateway
ApiGateway --> Lambda
Lambda --[store chat messages]--> MessageTable
Lambda --[store raw events]--> EventTable
Lambda --[send message]--> WhatsApp
Sequence diagram of the message flow:
sequenceDiagram
User->>WhatsApp: send message
WhatsApp->>ApiGateway: POST /
ApiGateway->>Lambda: proxy
Lambda->>EventTable: store raw event
Lambda->>OpenAI: generate response
OpenAI->>Lambda: response
Lambda->>MessageTable: store chat message
Lambda->>WhatsApp: send message
WhatsApp->>User: message sent