AWS CLI Setup Basics
9 examples to get you started with AWS CLI Setup - 6 basic and 3 intermediate.
Busca en todas las páginas de la documentación
9 examples to get you started with AWS CLI Setup - 6 basic and 3 intermediate.
brew install awscli; on Windows use the MSI; on Linux use the bundled installer.pip install boto3, or Node.js 18+ with npm install @aws-sdk/client-sts.Check that AWS CLI v2 is on your PATH before configuring anything.
aws --version
# aws-cli/2.x.x Python/3.x.x Darwin/... exe/x86_64aws-cli/2 - v1 is end-of-support and behaves differently.Related: The AWS CLI as the SDK's Shared Credential Backbone - why this file matters to your code.
aws configure collects an access key, secret, region, and output format, then saves them.
aws configure
# AWS Access Key ID [None]: AKIAEXAMPLE
# AWS Secret Access Key [None]: wJalrEXAMPLEKEY
# Default region name [None]: us-east-1
# Default output format [None]: json--profile flag, this writes to the [default] profile.~/.aws/credentials; region and output go into ~/.aws/config.Related: Named Profiles & Multi-Account Config - configure more than one account.
The two shared files are plain text and safe to read (keep them private).
# ~/.aws/credentials
[default]
aws_access_key_id = AKIAEXAMPLE
aws_secret_access_key = wJalrEXAMPLEKEY# ~/.aws/config
[default]
region = us-east-1
output = json[default] header names the profile; other profiles get their own headers.~/.aws/ patterns to your global gitignore.aws sts get-caller-identity is the fastest proof that your setup authenticates.
aws sts get-caller-identity
# {
# "UserId": "AIDAEXAMPLE",
# "Account": "123456789012",
# "Arn": "arn:aws:iam::123456789012:user/you"
# }InvalidClientTokenId or AuthFailure error means the key is wrong, disabled, or deleted.The SDKs read the profile you just configured with no keys in code.
# --- Python (boto3) ---
import boto3
sts = boto3.client("sts") # resolves the default profile
identity = sts.get_caller_identity()
print(identity["Account"], identity["Arn"])// --- TypeScript (AWS SDK v3) ---
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
const sts = new STSClient({}); // resolves the default profile
const identity = await sts.send(new GetCallerIdentityCommand({}));
console.log(identity.Account, identity.Arn);Related: Environment Variables vs Config File Precedence - how the SDKs decide which credentials to use.
Region is required for most API calls, so make sure a default exists.
aws configure set region us-west-2
aws configure get region
# us-west-2aws configure set/get edit and read single settings without the full prompt flow.~/.aws/config, not the credentials file, because it is not a secret.AWS_REGION environment variable overrides this value when present.Add a second identity without disturbing your default.
aws configure --profile staging
# ...prompts for the staging account's key, secret, region...
aws sts get-caller-identity --profile staging--profile staging writes a [staging] block and reads it back for later commands.staging, prod-readonly) so intent is obvious.Related: Named Profiles & Multi-Account Config - the full multi-account layout.
AWS_PROFILE makes every command and SDK client in the shell use one profile.
export AWS_PROFILE=staging
aws sts get-caller-identity # uses staging, no flag neededBoth SDKs honor the same variable:
# --- Python (boto3) ---
import os, boto3
os.environ["AWS_PROFILE"] = "staging" # or set it in the shell before launch
sts = boto3.client("sts")
print(sts.get_caller_identity()["Account"])// --- TypeScript (AWS SDK v3) ---
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
process.env.AWS_PROFILE = "staging"; // or set it in the shell before launch
const sts = new STSClient({});
const id = await sts.send(new GetCallerIdentityCommand({}));
console.log(id.Account);AWS_PROFILE in the shell keeps profile choice out of your code entirely.process.env after a client is built can be missed.Confirm what identities the machine holds before switching between them.
aws configure list-profiles
# default
# staging
# prod-readonly
aws configure list --profile staging
# shows the resolved region, output, and credential source for staginglist-profiles enumerates every profile across both shared files.configure list shows where each value came from, which is invaluable when precedence surprises you.Related: AWS SSO / IAM Identity Center CLI Login - profiles backed by short-lived SSO credentials.
Stack versions: This page was written for the AWS CLI v2, 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