AI on AWS Basics
AWS's AI services can feel like a wall of brand names. This page turns that wall into a short tour.
Busca en todas las páginas de la documentación
AWS's AI services can feel like a wall of brand names. This page turns that wall into a short tour.
The goal is orientation, not depth. By the end you will know the three layers, which one to reach for on a first project, and how to make a real call to each of the most common services in both Python (boto3) and TypeScript (AWS SDK v3).
These examples run against services you can enable in minutes, so this doubles as a first-hour checklist.
pip install boto3 (boto3 1.43.x, Python 3.10+). TypeScript: install one client per service, for example npm install @aws-sdk/client-bedrock-runtime (Node.js 18+).aws configure, environment variables, or an IAM role. The SDK resolves them automatically.AWS_REGION. AI service and model availability varies by region, so prefer a well-supported region such as us-east-1.bedrock:InvokeModel, rekognition:DetectLabels).AWS AI divides into three layers, from most managed to most custom.
# --- Python (boto3) ---
# Layer 1: purpose-built task service (one job, no model to choose)
import boto3
rekognition = boto3.client("rekognition") # vision
# Layer 2: Amazon Bedrock (managed foundation models via one API)
bedrock = boto3.client("bedrock-runtime") # generative / language
# Layer 3: Amazon SageMaker AI (your own trained model on your endpoint)
sagemaker = boto3.client("sagemaker-runtime")// --- TypeScript (AWS SDK v3) ---
// Layer 1: purpose-built task service
import { RekognitionClient } from "@aws-sdk/client-rekognition";
const rekognition = new RekognitionClient({});
// Layer 2: Amazon Bedrock (managed foundation models)
import { BedrockRuntimeClient } from "@aws-sdk/client-bedrock-runtime";
const bedrock = new BedrockRuntimeClient({});
// Layer 3: Amazon SageMaker AI (your own endpoint)
import { SageMakerRuntimeClient } from "@aws-sdk/client-sagemaker-runtime";
const sagemaker = new SageMakerRuntimeClient({});Related: Mapping AWS's AI Surface - the full map of the landscape.
Match the shape of your problem to a layer.
# --- Python (boto3) ---
# "Read labels from a photo" -> Rekognition (task service)
# "Detect sentiment in reviews" -> Comprehend (task service)
# "Summarize or chat over text" -> Bedrock (foundation model)
# "Score with my own trained model" -> SageMaker AI (custom)
import boto3
comprehend = boto3.client("comprehend")// --- TypeScript (AWS SDK v3) ---
// "Read labels from a photo" -> Rekognition
// "Detect sentiment in reviews" -> Comprehend
// "Summarize or chat over text" -> Bedrock
// "Score with my own trained model" -> SageMaker AI
import { ComprehendClient } from "@aws-sdk/client-comprehend";
const comprehend = new ComprehendClient({});Related: Foundation Models vs Purpose-Built AI Services - choosing between the top two layers.
Task services take input and return a structured result - no prompt.
# --- Python (boto3) ---
import boto3
comprehend = boto3.client("comprehend", region_name="us-east-1")
result = comprehend.detect_sentiment(Text="This product is great!", LanguageCode="en")
print(result["Sentiment"]) # e.g. "POSITIVE"// --- TypeScript (AWS SDK v3) ---
import { ComprehendClient, DetectSentimentCommand } from "@aws-sdk/client-comprehend";
const comprehend = new ComprehendClient({ region: "us-east-1" });
const result = await comprehend.send(new DetectSentimentCommand({
Text: "This product is great!",
LanguageCode: "en",
}));
console.log(result.Sentiment); // e.g. "POSITIVE"Bedrock's Converse operation is the model-agnostic way to send a prompt.
# --- Python (boto3) ---
import boto3
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")
response = bedrock.converse(
modelId="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=[{"role": "user", "content": [{"text": "Give me one tip for AWS beginners."}]}],
)
print(response["output"]["message"]["content"][0]["text"])// --- TypeScript (AWS SDK v3) ---
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
const bedrock = new BedrockRuntimeClient({ region: "us-east-1" });
const response = await bedrock.send(new ConverseCommand({
modelId: "anthropic.claude-3-5-sonnet-20240620-v1:0",
messages: [{ role: "user", content: [{ text: "Give me one tip for AWS beginners." }] }],
}));
console.log(response.output?.message?.content?.[0]?.text);Converse keeps one request shape across providers, so modelId is the only swap.ConverseStream when you want tokens to arrive incrementally.Related: AWS AI/ML Pricing Models Compared - what token, hourly, and per-request billing mean.
Across every layer, the SDK shape is identical: client, request, response.
# --- Python (boto3) ---
import boto3
# Amazon Polly: turn text into speech (another task service).
polly = boto3.client("polly", region_name="us-east-1")
audio = polly.synthesize_speech(Text="Hello from AWS", OutputFormat="mp3", VoiceId="Joanna")
with open("hello.mp3", "wb") as f:
f.write(audio["AudioStream"].read())// --- TypeScript (AWS SDK v3) ---
import { PollyClient, SynthesizeSpeechCommand } from "@aws-sdk/client-polly";
const polly = new PollyClient({ region: "us-east-1" });
const audio = await polly.send(new SynthesizeSpeechCommand({
Text: "Hello from AWS",
OutputFormat: "mp3",
VoiceId: "Joanna",
}));
// audio.AudioStream is a stream you write to a file or response.Related: AI on AWS Best Practices - the habits that carry across services.
Build the client once, and expect a permissions or access error on first use.
# --- Python (boto3) ---
import boto3
from botocore.exceptions import ClientError
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1") # module scope, reused
def ask(prompt: str) -> str:
try:
r = bedrock.converse(
modelId="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=[{"role": "user", "content": [{"text": prompt}]}],
)
return r["output"]["message"]["content"][0]["text"]
except ClientError as e:
# AccessDeniedException often means model access is not enabled yet.
return f"call failed: {e.response['Error']['Code']}"// --- TypeScript (AWS SDK v3) ---
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
const bedrock = new BedrockRuntimeClient({ region: "us-east-1" }); // module scope, reused
export async function ask(prompt: string): Promise<string> {
try {
const r = await bedrock.send(new ConverseCommand({
modelId: "anthropic.claude-3-5-sonnet-20240620-v1:0",
messages: [{ role: "user", content: [{ text: prompt }] }],
}));
return r.output?.message?.content?.[0]?.text ?? "";
} catch (e) {
// AccessDeniedException often means model access is not enabled yet.
return `call failed: ${(e as Error).name}`;
}
}Real features chain services - here Transcribe feeds Bedrock.
# --- Python (boto3) ---
import boto3
# 1. A task service turns audio into text (Transcribe job, simplified).
transcribe = boto3.client("transcribe", region_name="us-east-1")
# ... start a transcription job, then read its text output from S3 ...
transcript_text = "customer asked about a refund"
# 2. A foundation model summarizes the transcript.
bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")
summary = bedrock.converse(
modelId="anthropic.claude-3-5-sonnet-20240620-v1:0",
messages=[{"role": "user", "content": [{"text": f"Summarize: {transcript_text}"}]}],
)
print(summary["output"]["message"]["content"][0]["text"])// --- TypeScript (AWS SDK v3) ---
import { BedrockRuntimeClient, ConverseCommand } from "@aws-sdk/client-bedrock-runtime";
// 1. Assume a Transcribe job already produced this text.
const transcriptText = "customer asked about a refund";
// 2. A foundation model summarizes it.
const bedrock = new BedrockRuntimeClient({ region: "us-east-1" });
const summary = await bedrock.send(new ConverseCommand({
modelId: "anthropic.claude-3-5-sonnet-20240620-v1:0",
messages: [{ role: "user", content: [{ text: `Summarize: ${transcriptText}` }] }],
}));
console.log(summary.output?.message?.content?.[0]?.text);Related: The 2026 Generative AI Growth Curve on AWS - why generative work now anchors so many flows.
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: 24 jul 2026