This project creates a SecondLife chatbot service using AWS CDK. It deploys a serverless API that leverages the Mistral AI platform to provide conversational AI capabilities for SecondLife users.
The SecondLife Chatbot API is a serverless application built with AWS CDK that:
- Provides an API endpoint for SecondLife clients to interact with AI
- Uses Mistral AI for natural language processing
- Stores conversation history in S3 for context-aware responses
- Secures API access with API keys
- Uses AWS Parameter Store for sensitive credentials
The application consists of:
- API Gateway: Handles HTTP requests with API key authentication
- Lambda Function: Processes requests, interacts with Mistral AI, and manages chat history
- S3 Bucket: Stores conversation history for each user
- Parameter Store: Securely stores the Mistral API key
- AWS Account
- AWS CLI configured with appropriate credentials
- Node.js 18.x or later
- AWS CDK v2 installed globally (npm install -g aws-cdk)
- Mistral AI API key (sign up at https://mistral.ai)
- Clone this repository:
git clone <repo-url>
cd secondlife-chatbot-api
- Install dependencies:
npm install
- Bootstrap your AWS environment for CDK (if not already done):
cdk bootstrap
- Deploy the stack:
cdk deploy
- After deployment, update the Mistral API key in AWS Parameter Store:
- Navigate to AWS Systems Manager > Parameter Store
- Find the parameter named /secondlife-chatbot/mistral-api-key
- Edit the parameter and replace the placeholder value with your actual Mistral AI API key
API Endpoint The API provides a single endpoint that accepts POST requests:
POST https://{api-id}.execute-api.{region}.amazonaws.com/prod/
Authentication All requests must include an API key in the x-api-key header:
x-api-key: {your-api-key}
You can find the API key in the AWS Console under API Gateway > API Keys.
Request Format
{
"userId": "avatar-uuid-123",
"message": "Tell me about the history of SecondLife"
}
- userId: Optional. A unique identifier for the user/avatar. If not provided, a new UUID will be generated.
- message: Required. The text message from the user.
Response Format
{
"userId": "avatar-uuid-123",
"response": "SecondLife is a virtual world that was launched in 2003 by Linden Lab..."
}
The service stores conversation history for each user in S3, which allows the AI to maintain context across multiple interactions. By default, chat histories expire after 10 days.
.
├── bin/
│ └── secondlife-chatbot-api.js # CDK app entry point
├── lib/
│ └── secondlife-chatbot-api-stack.js # Main stack definition
├── functions/
│ └── chatbot.js # Lambda function code
├── test/
│ └── secondlife-chatbot-api.test.js # CDK tests
└── README.md
To test the CDK infrastructure locally:
npm test
- Edit the stack definition in secondlife-chatbot-api-stack.js
- Edit the Lambda function in chatbot.js
- Run cdk diff to see changes
- Deploy with cdk deploy
To test the API endpoint:
curl -X POST \
https://{api-id}.execute-api.{region}.amazonaws.com/prod/ \
-H 'Content-Type: application/json' \
-H 'x-api-key: {your-api-key}' \
-d '{"userId": "test-user", "message": "Hello, how are you?"}'
To remove all deployed resources:
cdk destroy
Note: The S3 bucket is configured with RemovalPolicy.RETAIN to prevent accidental data loss, so you'll need to delete it manually if desired.
This project is licensed under the MIT License - see the LICENSE file for details.