The AWS CLI (aws) is the standard tool for scripting AWS from the terminal or CI. This card groups commands by service. All examples assume AWS CLI v2 and a configured profile (aws configure or environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION). Add --profile <name> to any command to use a non-default profile. For secrets storage in CI, see github-secrets.
Assume a cross-account or privileged role; returns temporary credentials.
aws sts get-session-token --duration-seconds 3600
Get temporary credentials for an IAM user; used with MFA.
# Assume a role and export credentials to the shelleval $(aws sts assume-role \ --role-arn arn:aws:iam::123456789:role/DeployRole \ --role-session-name deploy \ --query "Credentials.[AccessKeyId,SecretAccessKey,SessionToken]" \ --output text \ | awk '{print "export AWS_ACCESS_KEY_ID="$1" AWS_SECRET_ACCESS_KEY="$2" AWS_SESSION_TOKEN="$3}')
IAM commands
Command
What it does
aws iam list-users
List all IAM users.
aws iam get-user --user-name alice
User details and ARN.
aws iam list-attached-user-policies --user-name alice
Policies directly attached to a user.
aws iam list-roles
List all IAM roles.
aws iam get-role --role-name MyRole
Role trust policy and ARN.
aws iam simulate-principal-policy --policy-source-arn arn --action-names s3:PutObject --resource-arns arn:aws:s3:::bucket/*
Simulate whether an ARN can perform an action.
aws iam create-policy --policy-name MyPolicy --policy-document file://policy.json
Create a managed policy from a file.
Common gotchas
aws s3 sync does not delete by default. Add --delete to remove objects in the destination that are absent from the source. Without it, old files accumulate.
--output table is for humans; --output json is for scripts. Use --query with JMESPath to filter before assigning to variables.
Lambda --payload in CLI v2 requires JSON as a string or file://path. Plain '{}' works in bash; quote carefully in CI environments.
aws sts get-caller-identity is the fastest way to confirm which credentials are active. Run it first when commands fail with access denied.
aws lambda invoke with --invocation-type Event always returns HTTP 202, even if the function fails. Check CloudWatch logs to diagnose async failures.
Region is required for most services. Set AWS_DEFAULT_REGION or --region on each command; the config file default can be wrong in CI.