If you're building AI-powered apps on AWS, you've probably felt the sting of Bedrock inference costs. Every token counts — and when users hammer your app with similar or identical questions, you're paying for the same answer over and over again.
In this post I'll walk through a three-layer caching and optimization pipeline I built inside a single Lambda function backed by ElastiCache (Redis). By the end, you'll have a pattern that can dramatically reduce Bedrock calls in any support chatbot, internal knowledge assistant, or document Q&A tool you're shipping.
Here's what we're building:
User prompt → Hash Check → Semantic Check → Prompt Compression → Bedrock → Cache Write ↓ ↓ hash_hit semantic_hit
Enter fullscreen mode
Exit fullscreen mode
Architecture at a Glance
Component Role
AWS Lambda (Python) Caching logic, embedding, compression
Amazon ElastiCache (Redis 7.1) Persistent shared memory across invocations
Amazon Bedrock (Nova Micro) Foundation model, only called on a true miss
Titan Embeddings…