S3 via SDK Best Practices
This is the checklist to run before and after taking an S3 workload to production from the SDK.
Busca en todas las páginas de la documentación
This is the checklist to run before and after taking an S3 workload to production from the SDK.
Each item is a rule stated positively, with a one-line rationale. Work top to bottom - the groups run from how you move data, through request patterns and cost, to security and operations. Most rules apply whether you call S3 from boto3, the AWS SDK v3, or IaC.
upload_file/TransferConfig in boto3 and Upload from @aws-sdk/lib-storage in v3 give parallel multipart with retries for free.AbortMultipartUpload on failure and add an AbortIncompleteMultipartUpload lifecycle rule.download_file/TransferConfig or GetObject with Range instead of buffering whole files in memory.Reach for the helper, not a raw put, whenever a file is large.
# --- Python (boto3) ---
import boto3
s3 = boto3.client("s3")
# Managed multipart: parallel parts, retries, and progress for free.
s3.upload_file("big.bin", "my-bucket", "data/big.bin")// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
import { Upload } from "@aws-sdk/lib-storage";
import { createReadStream } from "node:fs";
const s3 = new S3Client({});
// Managed multipart: parallel parts, retries, and progress for free.
await new Upload({
client: s3,
params: { Bucket: "my-bucket", Key: "data/big.bin", Body: createReadStream("big.bin") },
}).done();get_paginator("list_objects_v2") or paginateListObjectsV2 instead of stopping at the 1,000-key page.DeleteObjects removes up to 1,000 keys per request - far cheaper than per-object deletes.GetObject.CopyObject keeps bytes inside S3; use multipart copy above 5 GB.503 SlowDown instead of hammering the service.ListObjectsV2 result briefly.ChecksumAlgorithm) so corruption is caught, not assumed away.Tune retries once on the client rather than wrapping every call.
# --- Python (boto3) ---
import boto3
from botocore.config import Config
# Adaptive retries handle S3 throttling (503 SlowDown) with smart backoff.
s3 = boto3.client("s3", config=Config(retries={"max_attempts": 10, "mode": "adaptive"}))// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
// Adaptive retries handle S3 throttling with smart backoff.
const s3 = new S3Client({ maxAttempts: 10, retryMode: "adaptive" });STANDARD_IA, Glacier, or DEEP_ARCHIVE and expire what you no longer need - it runs for free.s3:* on *.aws:SecureTransport bucket policy.RequestId/$metadata.requestId so AWS support can trace a specific call.Never tiering or expiring data, and polling buckets in loops. Lifecycle rules move cold data to cheaper classes for free, and event-driven patterns replace request-heavy polling. Together they cut the largest recurring costs.
Always through the managed transfer helper - upload_file/TransferConfig in boto3 or Upload from @aws-sdk/lib-storage in v3. It uses parallel multipart with retries, which a single PutObject cannot match above 5 GB or on flaky networks.
No. Create one client and reuse it. A shared client reuses the connection pool and resolved credentials, which lowers latency and overhead, especially in long-running services and warm Lambda invocations.
Use adaptive retry mode and spread high-throughput keys across prefixes. S3 scales per prefix and returns 503 SlowDown under load; adaptive retries back off correctly, and prefix distribution raises the ceiling.
A short-lived presigned URL scoped to one object and one method. Keep buckets private with Block Public Access enabled, and never rely on public ACLs, which are a common breach source.
Use DeleteObjects in batches of up to 1,000 keys, driven by a paginated ListObjectsV2. This is far cheaper and faster than per-object DeleteObject, and it is the standard way to empty a prefix or bucket.
Mostly yes. Private buckets, encryption, least-privilege policies, lifecycle rules, versioning, and tagging are architectural habits that apply whether you configure S3 from the SDK or from CloudFormation, CDK, or Terraform.
Polling turns one logical "did anything arrive?" into a stream of billed ListObjectsV2 calls and adds latency. S3 notifications and EventBridge push the event to your code the moment an object lands, cheaper and faster.
Only for existing code. For new querying, use Amazon Athena for dataset SQL, S3 Object Lambda for on-read transforms, or client-side filtering for small objects. S3 Select is a single-object legacy API.
Abort incomplete multipart uploads. Call AbortMultipartUpload on error and add an AbortIncompleteMultipartUpload lifecycle rule so orphaned parts, which bill invisibly, are swept automatically.
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