Core SDK Mechanics Basics
Six short examples that show what a client actually does when you build it and call it.
Busque em todas as páginas da documentação
Six short examples that show what a client actually does when you build it and call it.
Each example shows the same operation in both Python (boto3) and TypeScript (AWS SDK for JavaScript v3), so you can see the mechanics translate one to one.
pip install boto3 (boto3 1.43.x, Python 3.10+). TypeScript: npm install @aws-sdk/client-s3 (Node.js 18+).aws configure, environment variables, or an IAM role.The region you pass is what drives endpoint resolution, so always set it.
# --- Python (boto3) ---
import boto3
s3 = boto3.client("s3", region_name="us-east-1")
print(s3.meta.region_name) # us-east-1// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "us-east-1" });
console.log(await s3.config.region()); // us-east-1region_name / region makes behavior reproducible across machines.Related: Regions, Endpoints & Client Construction - why region is mandatory.
You can read the hostname the SDK computed before sending anything.
# --- Python (boto3) ---
import boto3
s3 = boto3.client("s3", region_name="eu-west-1")
print(s3.meta.endpoint_url) # https://s3.eu-west-1.amazonaws.com// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "eu-west-1" });
const endpoint = await s3.config.endpoint?.();
console.log(endpoint?.hostname); // s3.eu-west-1.amazonaws.comclient.meta.endpoint_url.config.endpoint() returning a parsed URL object.Retries, timeouts, and endpoint variants are set through config.
# --- Python (boto3) ---
import boto3
from botocore.config import Config
cfg = Config(retries={"max_attempts": 5, "mode": "standard"})
s3 = boto3.client("s3", region_name="us-east-1", config=cfg)// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
const s3 = new S3Client({
region: "us-east-1",
maxAttempts: 5, // total attempts, including the first
retryMode: "standard",
});botocore.config.Config object passed as config.max_attempts counts total tries; the default retry mode already handles throttling.Related: Timeouts & Connection Configuration - the timeout knobs in depth.
Every response includes metadata alongside the business data.
# --- Python (boto3) ---
import boto3
s3 = boto3.client("s3", region_name="us-east-1")
resp = s3.list_buckets()
print(resp["ResponseMetadata"]["RequestId"])
print(resp["ResponseMetadata"]["HTTPStatusCode"]) # 200// --- TypeScript (AWS SDK v3) ---
import { S3Client, ListBucketsCommand } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "us-east-1" });
const resp = await s3.send(new ListBucketsCommand({}));
console.log(resp.$metadata.requestId);
console.log(resp.$metadata.httpStatusCode); // 200ResponseMetadata key of the response dict.$metadata property on the response object.Failed calls surface as typed errors that carry a service error code.
# --- Python (boto3) ---
import boto3
from botocore.exceptions import ClientError
s3 = boto3.client("s3", region_name="us-east-1")
try:
s3.head_bucket(Bucket="a-bucket-that-does-not-exist-xyz")
except ClientError as err:
print(err.response["Error"]["Code"]) # 404
print(err.response["ResponseMetadata"]["RequestId"])// --- TypeScript (AWS SDK v3) ---
import { S3Client, HeadBucketCommand } from "@aws-sdk/client-s3";
const s3 = new S3Client({ region: "us-east-1" });
try {
await s3.send(new HeadBucketCommand({ Bucket: "a-bucket-that-does-not-exist-xyz" }));
} catch (err) {
const e = err as { name: string; $metadata?: { requestId?: string } };
console.log(e.name); // NotFound
console.log(e.$metadata?.requestId);
}ClientError; read the code from err.response["Error"]["Code"].name is the service error code.Point the client at a local emulator by supplying an explicit endpoint.
# --- Python (boto3) ---
import boto3
# Override bypasses resolution: the SDK sends exactly here.
s3 = boto3.client(
"s3",
region_name="us-east-1",
endpoint_url="http://localhost:4566", # LocalStack
)// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
// Override bypasses resolution: the SDK sends exactly here.
const s3 = new S3Client({
region: "us-east-1",
endpoint: "http://localhost:4566", // LocalStack
});Related: Custom Endpoints & VPC Endpoints (PrivateLink) - overrides for private connectivity.
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 atualização: 23 de jul. de 2026