AWS CLI
config file
credentials file
configuration
cloud computing

AWS CLI config file vs credentials file

Codemia Knowledge Hub ·

~/.aws/credentials holds secrets: aws_access_key_id, aws_secret_access_key and session tokens. ~/.aws/config holds non-secret profile settings such as region, output, role assumption and SSO settings, and other CLI behavior. The CLI can read some overlapping values from both files, but keeping to that split is the clearest way to work.

Example layout of both files

~/.aws/credentials:

ini
1[default]
2aws_access_key_id = AKIAEXAMPLE
3aws_secret_access_key = secret-example
4
5[dev]
6aws_access_key_id = AKIADEVEXAMPLE
7aws_secret_access_key = dev-secret-example

~/.aws/config:

ini
1[default]
2region = us-west-2
3output = json
4
5[profile dev]
6region = us-east-1
7output = yaml

Profile header syntax differs between the files

  • in credentials, a named profile is [dev]
  • in config, a named profile is [profile dev]

This detail causes a lot of confusion.

Why secrets and settings are separate

Keeping secrets apart from general configuration makes both easier to reason about:

  • credentials may be rotated often
  • config may include region, SSO or role settings that are not secret
  • automation may manage one file differently from the other

Which file wins when both set a value

The AWS CLI documentation notes that the CLI can read overlapping settings from both files. If the same credential keys appear in both files for the same profile, the credentials file takes precedence for those values.

Put secrets in credentials and general profile configuration in config, and you avoid the ambiguity altogether.

Role and SSO profiles go in config

The config file carries the more advanced profile types:

  • role assumption profiles
  • SSO profiles
  • settings like region, output and source_profile

Example:

ini
1[profile prod-admin]
2role_arn = arn:aws:iam::123456789012:role/Admin
3source_profile = dev
4region = us-east-1

Checking which values the CLI is using

bash
aws configure list --profile dev

This helps when you are unsure whether a region came from the config file, an environment variable or another source.

To set a value without hand-editing the files:

bash
aws configure set region us-west-2 --profile dev

The command writes to the appropriate configuration store for you.

Some setups put more settings in one file than this split suggests. The CLI supports some of that, but a profile that works is not necessarily easy to maintain, and for most teams the conventional split is still the better choice.

Mistakes that cause profile confusion

  • Forgetting the profile header syntax difference between the two files.
  • Putting non-secret profile configuration in credentials, which makes the setup harder to follow over time.
  • Overlooking precedence and editing the wrong file while debugging a profile.
  • Forgetting that environment variables and other credential sources can override file-based settings, so the files are not the only source the CLI considers.

Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design