Pirate Cheat Sheets
The AWS SDK for Python

boto3
cheat sheet

boto3 at a glance: credentials, sessions and clients, S3, DynamoDB, SQS, Lambda, Secrets Manager, STS, paginators, waiters, errors and retries.

Version
v1.44.10
Snippets
70
Sections
8

Version notes · boto3 1.44.10

  • 1.44: standard is now the default retry mode: 3 attempts (4 for DynamoDB), throttling backs off 1 s.
  • Credentials from aws login (console sign-in) work out of the box, next to SSO and profiles.
  • S3 uploads send a CRC checksum by default (since 1.36). Some S3-compatible stores need request_checksum_calculation="when_required".
  • Resources (boto3.resource) still work but get no new features: prefer clients for new code.

The official AWS SDK for Python. A client per service exposes every API call as a method, generated from AWS’s service models (via botocore).

CoversS3DynamoDBSQSSNSLambdaSTSSecrets Manager300+ more

Every service

one client per AWS service

Credential chain

env, profile, SSO, IAM role

Paginators

iterate all pages for you

Retries built in

standard mode by default

Quick start

uv add boto3aws sso login --profile devAWS_PROFILE=dev uv run python -c "import boto3; print(boto3.client('sts').get_caller_identity()['Arn'])"

Install & sign in

  • Add the SDK
  • Type hints + autocomplete per service
  • Set up an SSO profile (AWS CLI)
  • Refresh SSO credentials
  • Sign in with console credentials

Environment variables

  • Profile from ~/.aws/config
  • Region (boto3 ignores AWS_REGION)
  • Static keys (+ AWS_SESSION_TOKEN)
  • Point every client elsewhere (LocalStack)
  • Retry attempts (AWS_RETRY_MODE too)

~/.aws/config

[profile dev]sso_session = corpsso_account_id = 123456789012sso_role_name = Developerregion = eu-west-1[sso-session corp]sso_start_url = https://corp.awsapps.com/startsso_region = eu-west-1[profile deploy]source_profile = devrole_arn = arn:aws:iam::…:role/Deploy

Lookup order: arguments → env vars → ~/.aws files (SSO, aws login, role chains) → container / EC2 instance role. Never hard-code keys.

  • Client from the default session
  • Pick a region
  • Session for one profile
  • Client from that session
  • S3-compatible store (MinIO, R2, LocalStack)
  • Client tuning
  • Retry mode: standard · adaptive · legacy
  • Timeouts (default 60 s each)
  • Pool size for threads (default 10)
  • Use a config
  • Resolved keys (debugging)

Clients are thread-safe; sessions are not. Create one client per service and reuse it. In Lambda, create it outside the handler.

Files & objects

  • Upload a file (multipart when large)
  • With metadata / ACL / SSE
  • Download to a file
  • From an open binary file
  • Small object from bytes
  • Read an object
  • Metadata only
  • Server-side copy
  • Delete one
  • Delete up to 1000

List & share

  • First 1000 keys (use a paginator)
  • "Folders" at the top level
  • Temporary download link
  • Temporary upload link (PUT)
  • Browser form upload (url + fields)
  • New bucket outside us-east-1
  • Paginator for a list call
  • Every page, no ContinuationToken juggling
  • JMESPath over all pages
  • Stop early
  • Is there a paginator?
  • Poll until something is true
  • Polling interval / limit
  • Available waiters
  • Plain Python types in and out
  • Condition builders
  • Create / replace
  • Read one (None if missing)
  • Query a partition
  • Sort-key condition
  • Query an index
  • Scan + filter (reads everything)
  • Update in place
  • Insert only if new
  • Buffered writes: batch.put_item(Item=…)
  • Delete

Numbers come back as decimal.Decimal. Use json.dumps(item, default=str) or convert them before serializing.

SQS & SNS

  • Send
  • Long-poll
  • Ack a message
  • Publish to a topic

Lambda, secrets, identity

  • Invoke and read the result
  • Fire and forget
  • Secrets Manager
  • Parameter Store
  • Who am I?
  • Temporary role credentials
  • Every error AWS returns
  • NoSuchKey, AccessDenied, ThrottlingException…
  • HTTP status
  • Modeled errors live on the client
  • Failed ConditionExpression
  • No credentials found
  • Network / wrong region

head_object has no body, so a missing key raises a plain ClientError with code 404, not NoSuchKey.

  • Log every request & retry
  • Region the client uses
  • Hook into the request lifecycle
  • Stub responses for unit tests
  • Fake AWS in-process (uv add --dev "moto[s3]")
  • Decorate a test: no real calls