Skip to content
Kuza Ndoto Academy

The AWS CLI & SDKs (boto3)

Beginner → IntermediateChapter 2 · Page 8 of 304 min readUpdated 15 Nov 2026

The AWS Command Line Interface (CLI) lets you manage AWS by typing commands, and the AWS SDKs let your own programs do the same. For Python, the SDK is called boto3. Both are faster than clicking once you know them, and both make your work repeatable.

Installing the CLI (version 2)

Always install AWS CLI version 2; version 1 is older and differs in places.

  • Windows: download and run the official MSI installer from the AWS CLI documentation.
  • macOS: run the official .pkg installer.
  • Linux (x86_64):
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
aws-cli/2.31.4 Python/3.13.7 Linux/6.8.0-48-generic exe/x86_64.ubuntu.24

Your version numbers will differ. AWS CloudShell, a browser terminal in the console, comes with the CLI preinstalled and already signed in, which is handy when you cannot install software.

Signing in: two ways

Recommended: IAM Identity Center (SSO)

If you set up Identity Center (see Creating an AWS Account Safely), run aws configure sso once. It asks for your access portal URL, opens a browser to approve the login, lets you pick an account and permission set, and saves a named profile:

$ aws configure sso
SSO session name (Recommended): kuza
SSO start URL [None]: https://d-1234567890.awsapps.com/start
SSO region [None]: eu-west-1
SSO registration scopes [sso:account:access]:
(browser opens; approve the request)
There are 2 roles available to you.
(use the arrow keys to choose AdministratorAccess)
Default client Region [None]: eu-west-1
CLI default output format (json if not specified) [None]: json
Profile name [AdministratorAccess-123456789012]: kuza-admin

Afterwards, when your session expires, log in again with one command:

aws sso login --profile kuza-admin

The CLI caches short-lived credentials and refreshes them; nothing permanent is stored on your laptop.

Fallback: access keys with aws configure

If you must use an IAM user's access key, aws configure stores it:

$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: eu-west-1
Default output format [None]: json

These are AWS's documentation dummy values. The key is saved in plain text in ~/.aws/credentials, and settings in ~/.aws/config. Keep those files out of every Git repository.

Your first commands

Check who you are signed in as. This is the first thing to run when something behaves strangely:

aws sts get-caller-identity --profile kuza-admin
{ "UserId": "AROAEXAMPLEID1234567:amina", "Account": "123456789012", "Arn": "arn:aws:sts::123456789012:assumed-role/AWSReservedSSO_AdministratorAccess_0123456789abcdef/amina" }

To avoid typing --profile every time, set an environment variable for the session with export AWS_PROFILE=kuza-admin (macOS/Linux) or $env:AWS_PROFILE = "kuza-admin" (PowerShell).

Working with S3 (the outputs depend on your account and are examples):

aws s3 mb s3://kuza-notes-demo-2026
aws s3 cp results.csv s3://kuza-notes-demo-2026/reports/results.csv
aws s3 ls
aws s3 ls s3://kuza-notes-demo-2026/reports/
make_bucket: kuza-notes-demo-2026 upload: ./results.csv to s3://kuza-notes-demo-2026/reports/results.csv 2026-11-10 09:14:22 kuza-notes-demo-2026 2026-11-10 09:15:03 2048 results.csv

The aws s3 commands are high-level helpers. The aws s3api commands map one-to-one to the S3 API and give you every option:

aws s3api head-object --bucket kuza-notes-demo-2026 --key reports/results.csv

Shaping output with --query and --output

--query filters JSON using JMESPath, and --output chooses json, yaml, text or table. The instances shown are an example:

aws ec2 describe-instances \
    --query "Reservations[].Instances[].[InstanceId, InstanceType, State.Name]" \
    --output table
-------------------------------------------------- | DescribeInstances | +----------------------+------------+------------+ | i-0abc1234def567890 | t3.micro | running | | i-0fed9876cba543210 | t3.small | stopped | +----------------------+------------+------------+

Other useful global options are --region and --no-cli-pager (stops the CLI opening long output in a pager).

boto3: AWS from Python

python -m pip install boto3

boto3 finds credentials automatically, in this order of common sources: environment variables, your ~/.aws profiles (including SSO profiles), then the role of the container, Lambda function or EC2 instance it runs on. That is why the same code works on your laptop and on AWS without any keys inside it.

import boto3
from botocore.exceptions import ClientError

session = boto3.Session(profile_name="kuza-admin", region_name="eu-west-1")
s3 = session.client("s3")

# List buckets
response = s3.list_buckets()
for bucket in response["Buckets"]:
    print(bucket["Name"], bucket["CreationDate"].date())

# Upload a file
try:
    s3.upload_file("results.csv", "kuza-notes-demo-2026", "reports/results.csv")
    print("Uploaded reports/results.csv")
except ClientError as err:
    print("Upload failed:", err.response["Error"]["Code"])

# A link that lets someone download the file for one hour
url = s3.generate_presigned_url(
    "get_object",
    Params={"Bucket": "kuza-notes-demo-2026", "Key": "reports/results.csv"},
    ExpiresIn=3600,
)
print(url[:60] + "...")
kuza-notes-demo-2026 2026-11-10 Uploaded reports/results.csv https://kuza-notes-demo-2026.s3.amazonaws.com/reports/result...

This output is an example; your bucket list depends on your account, and the exact URL format can vary by Region and settings. When your code runs on AWS, drop profile_name and just call boto3.client("s3") so the role's credentials are used.

Note

boto3 has two styles: clients (boto3.client("s3")), which map directly to API operations and return dictionaries, and resources (boto3.resource("dynamodb")), a more object-oriented layer. AWS no longer adds new features to resources, so prefer clients for new code; the DynamoDB Table resource is still common because it handles data types neatly.

Common mistake

Writing boto3.client("s3", aws_access_key_id="AKIA...", aws_secret_access_key="...") in your script. The keys end up in Git sooner or later. Let boto3 find credentials from your profile or role instead.

Key points

  • Install AWS CLI v2, or use CloudShell in the browser.
  • Prefer aws configure sso profiles (short-lived credentials) over aws configure with access keys.
  • Run aws sts get-caller-identity to check which identity and account you are using.
  • Use --query, --output, --region and --profile to control commands.
  • boto3 finds credentials automatically, so never hard-code keys in Python.
Up next · New chapter: ComputeAmazon EC2Virtual servers in the cloud: instance types, AMIs and pricing models.
→

Tip: use the ← and → keys to move between pages.