How to see what profile is default with CLI?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When people ask which profile is default in a CLI, they are usually dealing with tools that support multiple named credential sets, such as AWS CLI. The confusion comes from precedence rules, because command flags, environment variables, and config files can all override each other. The safest approach is to inspect effective runtime configuration, not only static files.
Understand What Default Means in Practice
In many CLIs, the word default does not mean one fixed value in one fixed file. It means the profile that will be selected for this specific command execution.
For AWS CLI specifically, profile selection usually follows this order:
- Explicit command flag such as
--profile dev. - Environment variable such as
AWS_PROFILE. - Fallback profile name
defaultin config and credentials files.
Because of that order, opening your config file and seeing [default] does not guarantee that your current shell session uses it.
Check Effective Profile in Your Current Shell
Start with shell-level visibility. This detects overrides before you run any command that talks to cloud services.
Then inspect resolved configuration from AWS CLI.
This output shows where each value came from, such as environment variable or shared config file. That source column is often more useful than the value itself when debugging profile behavior.
List all known profiles:
If you see only one profile and no environment override, your effective default is usually the default profile.
Build a Reusable Default-Profile Check Script
If your team frequently switches profiles, a small script reduces mistakes.
This script does not guess. It reports active environment overrides and then prints the resolved config source data.
Verify by Identity, Not Only by Profile Name
A profile name can point to unexpected credentials after edits, shell reloads, or role chaining changes. Always verify with an identity command when you need certainty.
For explicit comparison:
This confirms which account and principal are actually being used.
Diagnose Surprising Results
If output is not what you expect, check these areas in order:
- Shell environment variables.
- CLI version and plugin behavior.
- Shared config and credentials file paths.
- Wrapper scripts or aliases that inject
--profile.
Helpful checks:
If your environment uses custom paths, inspect those too:
Custom file locations are a frequent source of confusion in CI jobs and developer containers.
CI and Automation Guidance
In automation, implicit defaults are risky. Make profile choice explicit so jobs are reproducible.
Example in shell scripts:
Or pass profile directly on each command:
Also log identity at the start of a job. It is a low-cost check that prevents high-cost account mistakes.
Cross-Tool Notes
Many CLIs follow a similar model even if variable names differ:
- Env var override.
- Command flag override.
- Default named profile fallback.
The key lesson transfers across tools. Diagnose effective runtime profile first, then fix file-level configuration only if needed.
Common Pitfalls
- Assuming
[default]in config is always active. - Forgetting environment variables exported in old shell sessions.
- Using aliases or wrappers that silently add profile flags.
- Trusting profile names without verifying resolved caller identity.
- Relying on implicit defaults in CI pipelines.
Summary
- Default profile behavior is determined by runtime precedence, not one file entry.
- Check environment variables and
aws configure listbefore debugging deeper. - Validate with
sts get-caller-identitywhen account correctness matters. - Use explicit profile settings in automation for repeatable behavior.
- Treat profile diagnostics as part of operational safety, not only local convenience.

