Claude Function Calling on Bedrock: Wiring a Stateless Lambda for Real‑Time AI Actions A developer demonstrates how to wire Claude on Amazon Bedrock to a stateless Lambda for real-time AI actions, using function calling to trigger a DynamoDB update. The example shows a minimal TypeScript handler that parses an API Gateway event, invokes Claude with a tool definition, and handles the model's function call response. The approach keeps prompts short, makes systems extensible, and provides auditability by logging every function call. Developers love the idea of LLMs that can call your code, but most examples drown in boilerplate or require heavyweight orchestration. In just a few lines you can let Claude on Bedrock trigger a Lambda, update a DynamoDB table, and respond instantly to an API call. This post shows exactly how. Bedrock is Amazon’s managed service that hosts large language models LLMs like Claude. Function calling sometimes called tool use is a feature where the model can suggest that your program run a specific piece of code – for example, “add a new user”. The model returns a JSON payload that describes the function name and arguments. Your service reads that payload, runs the real function, and then sends the result back to the model so it can continue the conversation. In plain English:Think of the LLM as a helpful assistant that says, “Hey, could you add this person to the database?” and hands you a sticky note with the details. Your code reads the note, does the work, and tells the assistant “Done”. Why does this matter? Instead of hard‑coding all possible business logic into prompts, you let the model decide when to invoke real code. This keeps prompts short, makes the system extensible, and gives you auditability – you can log every function call. | Piece | What it is | Why you need it | |---|---|---| Tool definition | JSON that tells Bedrock what functions are available name, description, parameter schema | The model can only call functions it knows about | ToolResult field | The part of the response that contains the model’s chosen function call | Without it, you never see the request to run your code | Streaming vs non‑streaming | stream=true returns a series of Server‑Sent Events SSE ; stream=false returns a single JSON payload | Streaming lets you forward the answer to the caller as soon as it’s ready, but changes the shape of the result | Tip:The same TypeScript interface won’t match both shapes. Write two narrow types or a discriminated union and let the compiler help you. A Lambda is a short‑lived function that runs in AWS without you managing servers. We’ll use Node.js 22 the current LTS and TypeScript for type safety. Why start with a bare‑bones handler? It isolates the Bedrock call from any other infrastructure, making the example easy to copy‑paste into the AWS console or a CDK stack. js // src/lambda.ts import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda'; import { BedrockRuntimeClient, InvokeModelWithResponseStreamCommand, InvokeModelCommand, } from '@aws-sdk/client-bedrock-runtime'; import { DynamoDBDocumentClient, PutCommand } from '@aws-sdk/lib-dynamodb'; // Create a Bedrock client that talks to the Claude model in the same region const bedrock = new BedrockRuntimeClient { region: process.env.AWS REGION } ; // Create a DynamoDB client that works with plain JavaScript objects const ddb = DynamoDBDocumentClient.from new DynamoDBClient { region: process.env.AWS REGION } ; // The name of the DynamoDB table that stores users const USER TABLE = process.env.USER TABLE ; / Lambda entry point – receives an HTTP request from API Gateway, forwards it to Claude, handles any tool call, writes to DynamoDB, and returns a JSON response. / export const handler = async event: APIGatewayProxyEvent : Promise