Case Studies Basics
This page is a short tour across the four reference builds in this section, one wiring idea at a time.
Busca en todas las páginas de la documentación
This page is a short tour across the four reference builds in this section, one wiring idea at a time.
Each stop shows the smallest snippet that captures what makes that build's architecture distinctive - not the full system, which lives on its own page.
pip install boto3 (boto3 1.43.x, Python 3.10+). TypeScript: the per-service clients you use, for example npm install @aws-sdk/client-lambda @aws-sdk/client-dynamodb (Node.js 18+).The core idea behind Lambda + DynamoDB + API Gateway is turning one HTTP request into one table operation.
# --- Python (boto3) ---
import boto3, json
table = boto3.resource("dynamodb").Table("Tasks")
def handler(event, context):
body = json.loads(event["body"])
table.put_item(Item={"taskId": body["taskId"], "title": body["title"]})
return {"statusCode": 201, "body": json.dumps({"taskId": body["taskId"]})}// --- TypeScript (AWS SDK v3) ---
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
const doc = DynamoDBDocumentClient.from(new DynamoDBClient({}));
export const handler = async (event: any) => {
const body = JSON.parse(event.body);
await doc.send(new PutCommand({ TableName: "Tasks", Item: { taskId: body.taskId, title: body.title } }));
return { statusCode: 201, body: JSON.stringify({ taskId: body.taskId }) };
};statusCode, body) is what API Gateway turns back into an HTTP response.Related: Building a Serverless REST API: Lambda + DynamoDB + API Gateway.
The core idea behind a Bedrock RAG chatbot is retrieving grounding context before asking the model to answer.
# --- Python (boto3) ---
import boto3
bedrock_agent = boto3.client("bedrock-agent-runtime")
resp = bedrock_agent.retrieve_and_generate(
input={"text": "What is our refund window?"},
retrieveAndGenerateConfiguration={
"type": "KNOWLEDGE_BASE",
"knowledgeBaseConfiguration": {
"knowledgeBaseId": "KB123EXAMPLE",
"modelArn": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0",
},
},
)
print(resp["output"]["text"])// --- TypeScript (AWS SDK v3) ---
import { BedrockAgentRuntimeClient, RetrieveAndGenerateCommand } from "@aws-sdk/client-bedrock-agent-runtime";
const client = new BedrockAgentRuntimeClient({});
const resp = await client.send(new RetrieveAndGenerateCommand({
input: { text: "What is our refund window?" },
retrieveAndGenerateConfiguration: {
type: "KNOWLEDGE_BASE",
knowledgeBaseConfiguration: {
knowledgeBaseId: "KB123EXAMPLE",
modelArn: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0",
},
},
}));
console.log(resp.output?.text);RetrieveAndGenerate does the vector search and the model call in one managed step.Related: Building a RAG Chatbot: Bedrock + Knowledge Bases + S3 Vectors.
The core idea behind the data pipeline is a small Lambda function that only starts a Step Functions execution - it does not do the work itself.
# --- Python (boto3) ---
import boto3, json
sfn = boto3.client("stepfunctions")
def handler(event, context):
record = event["Records"][0]["s3"]
key = record["object"]["key"]
sfn.start_execution(
stateMachineArn="arn:aws:states:us-east-1:123456789012:stateMachine:LoadToRedshift",
input=json.dumps({"bucket": record["bucket"]["name"], "key": key}),
)// --- TypeScript (AWS SDK v3) ---
import { SFNClient, StartExecutionCommand } from "@aws-sdk/client-sfn";
const sfn = new SFNClient({});
export const handler = async (event: any) => {
const record = event.Records[0].s3;
await sfn.send(new StartExecutionCommand({
stateMachineArn: "arn:aws:states:us-east-1:123456789012:stateMachine:LoadToRedshift",
input: JSON.stringify({ bucket: record.bucket.name, key: record.object.key }),
}));
};Related: Building a Data Pipeline: S3 + Lambda + Step Functions + Redshift.
The core idea behind the refactor case study is replacing a per-item loop with a single batched call.
# --- Python (boto3) ---
# Before: one DynamoDB call per item in a loop.
# After: one BatchWriteItem call for up to 25 items.
table = boto3.resource("dynamodb").Table("Orders")
with table.batch_writer() as batch:
for order in orders:
batch.put_item(Item=order)// --- TypeScript (AWS SDK v3) ---
// Before: one PutCommand per item in a loop.
// After: one BatchWriteCommand for up to 25 items.
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, BatchWriteCommand } from "@aws-sdk/lib-dynamodb";
const doc = DynamoDBDocumentClient.from(new DynamoDBClient({}));
await doc.send(new BatchWriteCommand({
RequestItems: { Orders: orders.map((o: any) => ({ PutRequest: { Item: o } })) },
}));Related: Before/After: Refactoring a Monolithic SDK Integration.
Stack versions: This page was written for boto3 1.43.x (Python 3.10+) and the AWS SDK for JavaScript v3 (Node.js 18+).
Revisado por Chris St. John·Última actualización: 23 jul 2026