Integration
Use with AWS Lambda
Integrate duohub with AWS Lambda functions
Integrate duohub’s memory retrieval capabilities with AWS Lambda functions to query your knowledge graph through serverless functions.
Quick Start
Here’s our production-ready TypeScript implementation:
Prerequisites
- AWS Account with Lambda access
- Node.js 18 or later
- duohub API key
- AWS CLI configured (if deploying manually)
Setup Guide
1. Environment Variables
Set up your Lambda environment variable:
2. Dependencies
Required npm packages:
3. Deployment Options
Option A: Serverless Framework (Recommended)
Create a serverless.yml
:
Deploy with:
Option B: Manual Deployment
- Build the TypeScript:
- Create a ZIP with the compiled code and node_modules:
- Upload to AWS Lambda through the console or CLI
4. IAM Configuration
Minimum required IAM policy:
Usage
Request Format
Response Format
Testing
Test your deployed function with curl:
Best Practices
-
Error Handling
- Implement retries for network failures
- Add detailed logging
- Return meaningful error messages
-
Security
- Store API key in AWS Secrets Manager
- Use IAM roles with minimum required permissions
- Enable AWS X-Ray for request tracing
-
Performance
- Keep dependencies minimal
- Use connection pooling in axios
- Consider implementing caching if appropriate
-
Monitoring
- Set up CloudWatch alarms
- Monitor error rates and latency
- Set up logging for debugging
Troubleshooting
Common issues and solutions:
-
Timeout Issues
- Increase Lambda timeout in configuration
- Check duohub API response times
- Implement request timeouts in axios
-
Memory Issues
- Increase Lambda memory allocation
- Check for memory leaks
- Monitor memory usage patterns
-
Authorization Errors
- Verify API key is set