[{"data":1,"prerenderedAt":57},["ShallowReactive",2],{"snippet-lambda-durable-ai-parallel-invocation":3},{"id":4,"title":5,"contributors":6,"description":8,"extension":9,"gitHub":10,"introBox":13,"languages":19,"meta":22,"resources":23,"services":28,"snippets":31,"stem":49,"tags":50,"type":55,"__hash__":56},"snippets\u002Fsnippets\u002Flambda-durable-ai-parallel-invocation.json","Parallel Invocation with AWS Lambda durable functions",[7],"content\u002Fcontributors\u002Fconnor-kirkpatrick.json","Run multiple LLM prompts simultaneously with individual checkpointing using AWS Lambda durable functions","json",{"template":11},{"repoURL":12},"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Fsample-ai-workflows-in-aws-lambda-durable-functions",{"headline":14,"text":15},"How it works",[16,17,18],"This pattern demonstrates parallel invocation with AWS Lambda durable functions. Multiple LLM calls execute concurrently, with each response checkpointed independently.","The example sends multiple prompts about a topic in parallel, gathering different perspectives simultaneously.","Benefits: Faster execution through concurrent LLM calls. Individual checkpointing means partial failures don't require re-running successful calls. Automatic retry handling for each parallel operation.",[20,21],"Python","TypeScript",{},{"bullets":24},[25],{"text":26,"link":27},"AWS Lambda durable functions","https:\u002F\u002Faws.amazon.com\u002Flambda\u002Flambda-durable-functions\u002F",[29,30],"lambda-event-functions","bedrock",[32],{"title":33,"codeTabs":34},"Runtimes",[35,42],{"id":20,"title":36,"description":37,"snippets":38},"Usage Example with Python:","Parallel invocation with Lambda durable functions using Python.",[39],{"language":40,"code":41},"py","import boto3\nfrom aws_durable_execution_sdk_python import DurableContext, durable_execution\n\nMODEL_ID = \"us.amazon.nova-lite-v1:0\"\nbedrock = boto3.client(\"bedrock-runtime\")\n\n\ndef converse(model_id: str, prompt: str) -&#62; str:\n    response = bedrock.converse(\n        modelId=model_id,\n        messages=[{\"role\": \"user\", \"content\": [{\"text\": prompt}]}],\n    )\n    return response[\"output\"][\"message\"][\"content\"][0][\"text\"]\n\nPROMPTS = [\n    \"Explain the benefits of\",\n    \"Describe the challenges of\",\n    \"Summarize the future of\",\n]\n\n\n@durable_execution\ndef handler(event: dict, context: DurableContext):\n    topic = event.get(\"topic\", \"artificial intelligence\")\n\n    result = context.map(\n        PROMPTS,\n        lambda ctx, prompt, idx, items: {\n            \"prompt\": prompt,\n            \"response\": converse(MODEL_ID, f\"{prompt} {topic}\"),\n        },\n        \"Get perspectives\",\n    )\n\n    return {\"topic\": topic, \"perspectives\": result.get_results()}\n",{"id":21,"title":43,"description":44,"snippets":45},"Usage Example with TypeScript:","Parallel invocation with Lambda durable functions using TypeScript.",[46],{"language":47,"code":48},"ts","import {\n  type DurableContext,\n  withDurableExecution,\n} from \"@aws\u002Fdurable-execution-sdk-js\";\nimport {\n  BedrockRuntimeClient,\n  ConverseCommand,\n} from \"@aws-sdk\u002Fclient-bedrock-runtime\";\n\nconst MODEL_ID = \"us.amazon.nova-lite-v1:0\";\nconst bedrock = new BedrockRuntimeClient({});\n\nasync function converse(modelId: string, prompt: string): Promise&#60;string&#62; {\n  const response = await bedrock.send(\n    new ConverseCommand({\n      modelId,\n      messages: [{ role: \"user\", content: [{ text: prompt }] }],\n    }),\n  );\n  return response.output?.message?.content?.[0].text ?? \"\";\n}\n\nconst PROMPTS = [\n  \"Explain the benefits of\",\n  \"Describe the challenges of\",\n  \"Summarize the future of\",\n];\n\nexport const handler = withDurableExecution(\n  async (event: { topic?: string }, context: DurableContext) =&#62; {\n    const topic = event.topic ?? \"artificial intelligence\";\n\n    const result = await context.map(\n      \"Get perspectives\",\n      PROMPTS,\n      async (_, prompt) =&#62; ({\n        prompt,\n        response: await converse(MODEL_ID, `${prompt} ${topic}`),\n      }),\n      { itemNamer: (_, i) =&#62; `prompt-${i}` }\n    );\n\n    return { topic, perspectives: result.getResults() };\n  }\n);\n","snippets\u002Flambda-durable-ai-parallel-invocation",[51,52,30,53,54],"ai","durable-functions","genai","parallel","Integration","gal-Z1205h3Rn_FzfPuniMTa35Afy6S445F2AwL6bZ4",1792578864377]