🧠 Building an AI-Powered Life Coach with AWS Bedrock, Lambda, and DynamoDB
- Sangamesh Gella
- May 14
- 3 min read
Updated: May 17
In today's fast-paced world, having a supportive companion to guide and motivate us can make a significant difference. Leveraging the power of AWS, I embarked on a journey to build an AI-powered life coach that understands user inputs and retains context to provide personalised advice. This blog post outlines this endeavour's architecture, implementation, and insights.
🏗️ Architecture Overview
The solution integrates several AWS services to create a seamless and intelligent chatbot:
Amazon Lex: Serves as the conversational interface, capturing user inputs.
Amazon API Gateway: Acts as the entry point, routing requests to the backend.
AWS Lambda: Contains the core logic, orchestrating between services.
Amazon DynamoDB: Stores user interactions to maintain context.
Amazon Bedrock (Nova Pro Model): Processes inputs to generate empathetic and context-aware responses.

🧩 Component Breakdown
1. Amazon Lex
Lex captures user inputs and triggers the Lambda function. It provides a natural language interface, making interactions intuitive.
2. Amazon API Gateway
API Gateway exposes a RESTful endpoint, ensuring secure and scalable communication between the client and backend services.
3. AWS Lambda
The Lambda function performs the following:
Retrieves the user's last message from DynamoDB.
Constructs a prompt incorporating the previous and current messages.
Invokes the Amazon Bedrock Nova Pro model to generate a response.
Stores the latest user message back into DynamoDB.
4. Amazon DynamoDB
DynamoDB maintains a record of user interactions, enabling the chatbot to provide contextually relevant responses.
5. Amazon Bedrock (Nova Pro Model)
Bedrock's Nova Pro model processes the constructed prompt and returns a thoughtful, empathetic response tailored to the user's current state.
Here's a snippet of the Lambda function:
import json
import boto3
from datetime import datetime
dynamodb = boto3.client("dynamodb")
bedrock = boto3.client("bedrock-runtime")
TABLE_NAME = "ChatMemory"
def lambda_handler(event, context):
try:
headers = {k.lower(): v for k, v in event['headers'].items()}
user_id = headers.get("user-id", "anonymous")
body = json.loads(event['body'])
user_input = body.get("text", "Hello")
# Retrieve past message
memory_response = dynamodb.get_item(
TableName=TABLE_NAME,
Key={"userId": {"S": user_id}}
)
item = memory_response.get("Item")
past_note = item.get("lastMessage", {}).get("S", "") if item else ""
# Construct prompt
prompt = f"""You are a supportive life coach.
The user previously said: "{past_note}"
They now say: "{user_input}"
Respond with empathy and practical suggestions."""
# Invoke Bedrock
payload = {
"messages": [
{
"role": "user",
"content": [{"text": prompt}]
}
],
"inferenceConfig": {
"max_new_tokens": 500,
"temperature": 0.7
}
}
response = bedrock.invoke_model(
modelId="amazon.nova-pro-v1:0",
body=json.dumps(payload),
accept="application/json",
contentType="application/json"
)
response_body = json.loads(response['body'].read())
reply = response_body["output"]["message"]["content"][0]["text"]
# Store latest message
dynamodb.put_item(
TableName=TABLE_NAME,
Item={
"userId": {"S": user_id},
"lastMessage": {"S": user_input},
"lastUpdated": {"S": datetime.utcnow().isoformat()}
}
)
return {
"statusCode": 200,
"body": json.dumps({"message": reply})
}
except Exception as e:
return {
"statusCode": 500,
"body": json.dumps({"error": str(e)})
}
🧠 Key Learnings
Context Retention: Storing user interactions in DynamoDB allows the chatbot to provide personalised and context-aware responses.
Scalability: Leveraging AWS services ensures the solution can handle varying loads without manual intervention.
Modularity: Each component serves a distinct purpose, making the system maintainable and extensible.
🔮 Future Enhancements
Sentiment Analysis: Integrate Amazon Comprehend to gauge user emotions and adjust responses accordingly.
Multi-turn Conversations: Enhance the DynamoDB schema to store entire conversation histories.
Frontend Integration: Develop a user-friendly interface using AWS Amplify or other frontend frameworks.
Embarking on this project has been an enlightening experience, showcasing the power and flexibility of AWS services in building intelligent applications. I'm excited about the potential enhancements and look forward to sharing more insights. Stay tuned for more updates!
Comments