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:
~/.aws/config:
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,outputandsource_profile
Example:
Checking which values the CLI is using
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:
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.
Related reading
- aws cli ec2 describe-instances table output
- AWS CLI ECR list-images, get newest
- AWS CLI get download S3 URL for private bucket from AWS CLI
- AWS CLI Key is not in valid OpenSSH public key format
- AWS CLI listing S3 buckets gives SignatureDoesNotMatch error using IAM user credentials
- AWS CLI PATH Settings
- AWS CLI S3 A client error 403 occurred when calling the HeadObject operation Forbidden
- AWS CLI S3 copying file locally using the terminal fatal error An error occurred 404 when calling the HeadObject operation
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.