Back to articles
We Started with Lambdas. Here's What Broke.
How-ToDevOps

We Started with Lambdas. Here's What Broke.

via Dev.toTyson Cung

Lambdas seemed perfect for AI workloads. Single-purpose functions, automatic scaling, pay only for what you use. We built 7 of them before realizing our mistake. Here's our first Lambda - a document summarizer for our asset management platform: import { APIGatewayProxyHandler } from ' aws-lambda ' ; import OpenAI from ' openai ' ; const openai = new OpenAI ({ apiKey : process . env . OPENAI_API_KEY , }); export const handler : APIGatewayProxyHandler = async ( event ) => { try { const { document } = JSON . parse ( event . body || ' {} ' ); const response = await openai . chat . completions . create ({ model : ' gpt-4 ' , messages : [ { role : ' system ' , content : ' Summarize the following document in 2-3 sentences. ' }, { role : ' user ' , content : document } ], max_tokens : 150 }); return { statusCode : 200 , body : JSON . stringify ({ summary : response . choices [ 0 ]. message . content }) }; } catch ( error ) { return { statusCode : 500 , body : JSON . stringify ({ error : error

Continue reading on Dev.to

Opens in a new tab

Read Full Article
6 views

Related Articles