Configure AWS CLI with the .aws/config File
Learn how to configure AWS CLI profiles, regions, output formats, IAM roles, IAM Identity Center, credentials, environment variables, and troubleshooting in ~/.aws/config.
The AWS Command Line Interface (AWS CLI) uses shared configuration files to remember settings such as regions, output formats, profiles, and role-assumption details. The main user-level configuration file is commonly ~/.aws/config on Linux and macOS, or %UserProfile%\.aws\config on Windows.
This guide explains how to create and manage that file, how it relates to the credentials file, and how AWS CLI resolves settings and credentials.
The .aws Directory
The .aws directory is a per-user directory commonly used by the AWS CLI and compatible SDKs for shared configuration, credentials, cached login data, and related files. It is located inside the current user's home directory.
| Platform | Default config path | Default credentials path | Notes |
|---|---|---|---|
| Linux | ~/.aws/config | ~/.aws/credentials | ~ means the current user's home directory. |
| macOS | ~/.aws/config | ~/.aws/credentials | The files are hidden because the directory name begins with a period. |
| Windows | %UserProfile%\.aws\config | %UserProfile%\.aws\credentials | %UserProfile% identifies the current Windows user's home directory. |
Config Versus Credentials
The config file stores non-secret CLI behavior and profile settings. The credentials file can store access keys and temporary session credentials. An external credential provider can supply credentials instead of either file.
| Characteristic | config | credentials |
|---|---|---|
| Typical path | ~/.aws/config | ~/.aws/credentials |
| Typical contents | Regions, output, retry behavior, role settings, SSO settings, and endpoints | Access keys, secret keys, and session tokens |
| Named profile header | [profile development] | [development] |
| Secret handling | Normally contains no long-term secrets | May contain sensitive credentials and must be protected |
Long-term access keys and secret access keys normally belong in the credentials file or an external credential provider, not in config. See the related AWS CLI credentials file guide.
Profiles and Section Names
A profile is a named collection of AWS CLI settings and, depending on the credential method, identity configuration. The default profile is used when no other profile is selected. A named profile separates settings for environments such as personal, development, staging, production, or another AWS account.
In the config file, use [default] for the default profile and [profile name] for every named profile:
[default]
region = us-east-1
output = json
[profile development]
region = us-west-2
output = yaml
Do not omit the profile prefix from a named section in config. The credentials file uses the shorter form, such as [development].
| Method | Example | Scope | Precedence considerations |
|---|---|---|---|
| Default profile | aws s3 ls | One command when no other profile is selected | Can be affected by environment variables. |
| Command option | aws s3 ls --profile development | One command | Explicit command options take precedence over profile defaults. |
| Environment variable | AWS_PROFILE=development | Current process or shell | Used when --profile is not supplied. |
Use a profile explicitly in scripts when the script must not depend on the user's default profile.
Core Configuration Settings
| Setting | Purpose | Typical use case | Security considerations |
|---|---|---|---|
region | Selects the default AWS Region and the default Regional service endpoint. | Directing commands to us-east-1 or another Region. | A wrong Region can target the wrong resources or produce misleading results. |
output | Controls result formatting. | json, yaml, yaml-stream, text, or table. | Choose a predictable format for automation. |
cli_pager | Controls whether output is sent through a pager. | Set cli_pager = to avoid interactive paging in scripts. | Prevents unattended jobs from waiting for input. |
cli_auto_prompt | Controls interactive command suggestions and prompting. | Enable it while learning commands, or disable it for automation. | Interactive behavior is usually unsuitable for unattended jobs. |
retry_mode | Selects the CLI retry strategy. | Using standard or adaptive retry behavior for transient failures. | Retries do not replace correct permissions or safe idempotent operations. |
max_attempts | Limits request attempts under the selected retry mode. | Controlling latency and retry volume. | Very low values can make transient failures more visible. |
endpoint_url | Sets a custom service endpoint. | Controlled testing, emulators, or approved private endpoints. | Verify the endpoint before sending sensitive data. |
The command-line option is the most direct one-off override. For example, --region eu-west-1 overrides a profile's region for that command. In general, command-line parameters override environment settings, which can override profile values.
Creating and Updating the Config File
Interactive setup
Run aws configure to set up the default profile interactively. The prompts commonly include an access key, secret access key, default Region, and output format. Avoid entering long-term keys when a role, IAM Identity Center, or another temporary credential method is available.
aws configure
Setting individual values
Use aws configure set to update one setting. Include --profile for a named profile:
aws configure set region us-west-2 --profile development
aws configure set output yaml --profile development
Editing the file directly
The file uses INI-style syntax: a section header in square brackets followed by key = value assignments. Keep one setting per line and use the exact profile header rules.
[profile development]
region = us-west-2
output = yaml
cli_pager =
retry_mode = standard
max_attempts = 4
After editing, inspect the result with:
aws configure list
aws configure list --profile development
aws configure list-profiles
aws configure list shows effective configuration sources, while list-profiles shows profiles discovered by the CLI.
Credentials and the Provider Chain
The AWS CLI uses a credential provider chain: an ordered process that checks multiple possible sources for usable credentials. The exact behavior can vary by CLI version and execution environment, but common sources include:
| Credential source | Where configured | Best suited for | Credential lifetime |
|---|---|---|---|
| Shared credentials | ~/.aws/credentials | Local development when another provider is unavailable | Static or temporary, depending on the values |
| Environment variables | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optionally AWS_SESSION_TOKEN | Short-lived shells and CI systems | Static or temporary |
| IAM role attached to compute | EC2 instance, ECS task, or another supported workload environment | Applications running on AWS | Temporary and refreshed by the environment |
| IAM Identity Center | SSO session and profile sections in config | Human workforce access | Temporary and login-based |
credential_process | A command in a profile | Enterprise credential helpers and vault integrations | Determined by the helper |
| Web identity tokens | web_identity_token_file and role_arn | Federated containers and workloads | Temporary |
Prefer temporary credentials, IAM roles, or IAM Identity Center over static keys. Never commit credentials to source control or place them in documentation, shell history, or broadly shared machines.
Assuming an IAM Role from a Profile
An IAM role is an AWS identity with permissions that can be assumed to obtain temporary credentials. A cross-account profile commonly uses a source profile for the initial identity and a target role for access to another account.
[profile engineering-admin]
role_arn = arn:aws:iam::123456789012:role/EngineeringAdmin
source_profile = development
role_session_name = cli-engineering-session
region = us-east-1
source_profileidentifies the profile that supplies the initial credentials.role_arnis the Amazon Resource Name that identifies the target role.role_session_namelabels the temporary role session for auditing.external_idsupplies a required third-party or confused-deputy protection value when the trust policy requires one.duration_secondsrequests the session duration, subject to the role and service limits.mfa_serialidentifies the MFA device when the role requires multi-factor authentication.
The source identity must be allowed to call sts:AssumeRole, and the target role's trust policy must allow that source principal. An access-denied error can result from either side.
IAM Identity Center Profiles
AWS IAM Identity Center provides workforce sign-in and temporary access to assigned AWS accounts and roles. Configure it interactively with:
aws configure sso
Modern configurations commonly separate reusable sign-in information into an sso-session section and account-specific access into a profile:
[sso-session company]
sso_start_url = https://example.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access
[profile company-readonly]
sso_session = company
sso_account_id = 123456789012
sso_role_name = ReadOnlyAccess
region = us-east-1
The session describes the IAM Identity Center portal and sign-in configuration. The profile references that session and selects an account and role assigned through the portal. Authenticate before use:
aws sso login --profile company-readonly
The CLI stores a local cached token and uses it until it expires or must be refreshed. An unattended job should not depend on an interactive login; use an appropriate workload role or automation credential provider instead.
Environment Variables and Precedence
AWS_PROFILEselects a profile for the current process.AWS_DEFAULT_REGIONsupplies a default Region.AWS_REGIONsupplies a Region in environments and tools that recognize it.AWS_CONFIG_FILEchanges the shared config file path.AWS_SHARED_CREDENTIALS_FILEchanges the shared credentials file path.AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_SESSION_TOKENprovide environment credentials. Session credentials require all relevant parts, including the session token.
Conceptually, command-line parameters override environment settings, and environment settings can override profile defaults. Credential resolution still follows the provider chain, so an environment credential, workload role, or external process may supply identity instead of the profile's credentials file.
Custom file paths are useful for isolated shells, tests, and automation:
export AWS_CONFIG_FILE="$PWD/test-config"
export AWS_SHARED_CREDENTIALS_FILE="$PWD/test-credentials"
aws configure list
On Windows PowerShell, equivalent environment assignment uses $env:AWS_CONFIG_FILE = "C:\path\to\config".
Advanced Profile Settings
External credential processes
credential_process runs an external program that returns credentials in the format expected by AWS tooling. Protect the helper and its output, and ensure the command cannot be replaced by an untrusted user.
[profile external-auth]
credential_process = /usr/local/bin/credential-helper --profile external-auth
region = eu-west-1
Web identity
A web identity token is a federated identity token used with a role to request temporary AWS credentials. This is common in containerized or orchestrated workloads:
[profile workload]
role_arn = arn:aws:iam::123456789012:role/WorkloadRole
web_identity_token_file = /var/run/secrets/token
region = us-east-1
source_profile and credential_source
source_profile points to another named profile for initial credentials. credential_source tells the CLI to obtain initial credentials from a supported execution environment instead, such as an attached instance role, an ECS container role, or the environment. Use the approach that matches where the initial identity is provided; do not combine incompatible source methods casually.
Endpoints, CA bundles, and proxies
endpoint_url can direct requests to a controlled custom endpoint. Service-specific endpoint configuration is useful when only one service needs a special address. Use custom endpoints only when required and verify them carefully.
Corporate network setups may also require a custom CA bundle so TLS certificates can be verified, or proxy-related configuration supplied through supported CLI or operating-system settings. A missing corporate CA certificate often causes TLS verification errors; disabling certificate verification is not a safe general solution.
Using Profiles in Commands and SDKs
# Use the default profile
aws s3 ls
# Select a named profile for one command
aws s3 ls --profile development
# Select a profile for the current shell
export AWS_PROFILE=development
aws sts get-caller-identity
Many AWS SDKs can read the shared config and credentials files when shared configuration loading is enabled or supported by that SDK. Check the SDK's documented configuration behavior before assuming that every CLI setting is recognized. In scripts, select a profile explicitly, avoid relying on interactive SSO login, and ensure temporary credentials can refresh without human input.
Security and Operational Practices
- Use least-privilege IAM permissions.
- Use separate profiles for separate accounts and environments.
- Prefer IAM Identity Center, IAM roles, or temporary credentials over static access keys.
- Restrict local file access. On Unix-like systems, protect credential files with permissions such as
chmod 600 ~/.aws/credentialswhere appropriate. - Do not commit
configorcredentialsfiles containing secrets to source control. - Do not paste secrets into tickets, documentation, shell history, or shared logs.
- Use clear names such as
company-dev,company-prod-readonly, andcompany-security. - Periodically remove unused profiles, expired keys, cached sessions, and obsolete role references.
Validation and Troubleshooting
Always verify the identity before making changes:
aws sts get-caller-identity
aws sts get-caller-identity --profile development
aws configure list
aws configure list-profiles
The --debug option can reveal profile resolution, endpoint selection, and authentication flow:
aws sts get-caller-identity --profile development --debug
| Symptom | Likely cause | How to verify | Resolution |
|---|---|---|---|
| Named profile cannot be found | Missing section, incorrect [profile name] syntax, wrong AWS_CONFIG_FILE, or a misspelled name | Run aws configure list-profiles and inspect the active file | Correct the section or selected name and unset an unintended custom file variable. |
| Unexpected Region | AWS_REGION, AWS_DEFAULT_REGION, or --region overrides the profile | Run aws configure list --profile name and inspect environment variables | Remove the unwanted override or use --region deliberately. |
| AssumeRole returns AccessDenied | Missing sts:AssumeRole, incorrect trust policy, missing MFA or external ID, or wrong role ARN | Verify the source identity and review both IAM policies | Correct the permission, trust relationship, required values, or ARN. |
| IAM Identity Center stops working | Cached login expired, incorrect SSO session, or changed account or role assignment | Run aws sso login --profile name and review SSO sections | Sign in again or correct the session and assignment. |
| Unexpected credentials are used | Environment credentials, another AWS_PROFILE, workload role, or credential_process is active | Use aws configure list and aws sts get-caller-identity; inspect environment variables | Remove unintended variables, choose the profile explicitly, or test in a clean shell. |
| Expired or invalid token | Temporary credentials or SSO login expired, or AWS_SESSION_TOKEN is missing | Identify the credential method and inspect all session values | Refresh the login or role session and provide the complete credential set. |
Practical Configuration Patterns
Default region and output
[default]
region = us-east-1
output = json
Named development profile
[profile development]
region = us-west-2
output = yaml
Separate static credentials from settings
# ~/.aws/config
[profile development]
region = us-west-2
# ~/.aws/credentials
[development]
aws_access_key_id = EXAMPLEACCESSKEY
aws_secret_access_key = EXAMPLESECRETKEY
The values above are placeholders, not usable credentials. In real environments, prefer a temporary or role-based source.
Exam-Relevant Notes
[default]names the default config profile; named config profiles use[profile name].- The config file normally stores behavior and profile settings; the credentials file can store access keys.
--profileselects one command's profile, whileAWS_PROFILEaffects the process environment.source_profileuses another profile's credentials for role assumption;credential_sourceobtains credentials from the execution environment.- Role assumption requires permission for the source identity and a trusting target role.
- IAM Identity Center profiles require an SSO login and use temporary credentials.
aws sts get-caller-identityis the quickest way to confirm the active AWS account and identity.