Authentication & Credential Rules Checklist
Leaked AWS credentials are the fastest route to a security incident and a surprise bill.
Busca en todas las páginas de la documentación
Leaked AWS credentials are the fastest route to a security incident and a surprise bill.
This checklist is the highest-impact page in the section. Walk it against any code that constructs an AWS client.
.aws/credentials, .env, and secrets files out of the deploy artifact and out of version control.aws_access_key_id / credentials literals defeats the chain and invites hardcoding.Let the default chain do the work - construct the client with no keys at all.
# --- Python (boto3) ---
import boto3
# Correct: no keys. The default chain finds env vars, shared config, or an IAM role.
s3 = boto3.client("s3", region_name="us-east-1")// --- TypeScript (AWS SDK v3) ---
import { S3Client } from "@aws-sdk/client-s3";
// Correct: no keys. The default provider chain resolves credentials.
const s3 = new S3Client({ region: "us-east-1" });sso profiles for human developers. Short-lived SSO sessions beat long-lived access keys on a laptop.AssumeRole (or a profile with role_arn) instead of copying another account's keys.Authorization header while debugging.printenv-style debugging in pipelines.region_name / region (or AWS_REGION) so the call does not depend on ambient defaults.Read the caller's identity when you need to confirm which credentials resolved.
# --- Python (boto3) ---
import boto3
sts = boto3.client("sts", region_name="us-east-1")
who = sts.get_caller_identity() # confirms which identity the chain resolved
print(who["Arn"]) # never print the credentials themselves// --- TypeScript (AWS SDK v3) ---
import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts";
const sts = new STSClient({ region: "us-east-1" });
const who = await sts.send(new GetCallerIdentityCommand({}));
console.log(who.Arn); // confirms the identity; never log credentialsgit-secrets or a pre-commit hook) so keys never reach history.Committed keys are scraped from public repositories within minutes and used to launch resources for crypto mining. The result is a large bill and a security incident at once.
The ordered search the SDK runs to find credentials: explicit config, environment variables, shared config files, then instance, container, or Lambda IAM roles.
Roles supply temporary credentials that rotate automatically and expire. There are no long-lived keys to store, leak, or forget to rotate.
With IAM Identity Center (SSO) profiles or named profiles that assume roles. These give short-lived credentials instead of static keys sitting on a laptop.
In AWS Secrets Manager or SSM Parameter Store as a SecureString. Fetch them at runtime rather than baking them into an image or a committed file.
No. It contains the SigV4 signature derived from your secret key. Redact credentials and signed headers from all logs and error reports.
Treat it as compromised. Deactivate it, confirm nothing legitimate breaks, then delete it and investigate what the key could reach.
You assume a role in the target account with STS instead of copying its keys. The credentials are temporary and scoped to that role's permissions.
Indirectly. Explicit region config makes resolution reproducible, so calls do not silently go to the wrong region with credentials that may not be valid there.
Run a secret scanner as a pre-commit hook and in CI. It blocks commits that contain key-shaped strings before they ever enter history.
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