Deploy and test a streaming-capable Lambda function using modern IaC tools and AI workflows. Built with cutting-edge AWS features and LLM integration!
- Lambda Response Streaming (AWS April 2023 feature) 💨
- Pulumi Infrastructure-as-Code (TypeScript flavor) 🏗️
- LangChain LCEL workflows integrated with AWS Bedrock (DeepSeek R1 model) ⚡
- Full-stack testing (Vitest + Pulumi Automation API) 🧪
- Zero-dependency deployment with
pnpm📦
- AWS Account (Free Tier OK)
- Node.js 18+
- pnpm
- AWS CLI configured with valid credentials
# Clone & setup
git clone https://github.com/renato1010/streaming-lambda-pulumi
cd streaming-lambda-pulumi
pnpm install
# Deploy infrastructure
pulumi up -y
# Run unit tests
pnpm vitest -t utils
# Execute integration tests
pnpm vitest -t streaming// Example Vitest case
const base64String = 'eyJxdWVzdGlvbiI6IldoYXQncyBHZW5lcmF0aXZlIEFJLCBpbiAyMDAgY2hhcnMgb3IgbGVzcyJ9';
const expectedJsonString = `{"question":"What's Generative AI, in 200 chars or less"}`;
it('should decode base64', () => {
const jsonString = decodeBase64String(base64String, true);
expect(jsonString).toEqual(expectedJsonString);
});
it('should validate body payload against schema', () => {
const bodyString = expectedJsonString;
const validatedBody = queryBodySchemaValidator(bodyString, queryHandlerSchema);
expect(validatedBody).toStrictEqual(JSON.parse(expectedJsonString));
});// Pulumi Automation API integration test
it('should have a streaming URL', async () => {
const outputs = await getOutputs();
const streamingUrl: string = outputs['streamingURL'].value;
expect(streamingUrl).toBeDefined();
});
it('should return a response stream', { timeout: 60000 }, async () => {
const outputs = await getOutputs();
const streamingUrl: string = outputs['streamingURL'].value;
const response = await fetch(streamingUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'text/event-stream'
},
body: JSON.stringify({
question: "What's Generative AI, in 200 chars or less"
})
});
expect(response.status).toBe(200);
expect(response.headers.get('Content-Type')).toBe('text/event-stream');
});tests/streaming-function.test.ts, you'll need to redeploy your
infrastructure by running:
pulumi uphttp --stream POST $(pulumi stack output streamingURL ) \
question="What's Generative AI, in 200 chars or less"| Component | Role |
|---|---|
| 🐑 Pulumi | IaC orchestration |
| ⚡ AWS Lambda Streaming | Chunked response delivery |
| 🔗 LangChain LCEL(TS) | Langchain Expression Language(Runnable) |
| 🤖 AWS Bedrock | DeepSeek R1 model |
| 🧪 Vitest | Unit/component testing |
| 🤖 Pulumi Automation API | Infrastructure validation |
Found this useful? ⭐ Star the repo _License: MIT 📜
