Configuration and credential file settings in the AWS CLI
You can save your frequently used configuration settings and credentials in files that are maintained by the AWS CLI.
The files are divided into profiles. By default, the AWS CLI uses the settings
found in the profile named default. To use alternate settings, you can create
and reference additional profiles.
You can override an individual setting by either setting one of the supported environment variables, or by using a command line parameter. For more information on configuration setting precedence, see Configuring settings for the AWS CLI.
Note
For information on setting up your credentials, see Authentication and access credentials for the AWS CLI.
Topics
Format of the configuration and credential files
The config and credentials files are organized into
sections. Sections include profiles,
sso-sessions, and services. A section is a named collection of settings, and
continues until another section definition line is encountered. Multiple profiles and
sections can be stored in the config and
credentials files.
These files are plaintext files that use the following format:
-
Section names are enclosed in brackets [ ] such as
[default],[profile, anduser1][sso-session]. -
All entries in a section take the general form of
setting_name=value. -
Lines can be commented out by starting the line with a hash character (
#).
The config and credentials files contain the following section types:
Section type: profile
Depending on the file, profile section names use the following format:
-
Config file:
[default][profileuser1] -
Credentials file:
[default][user1]Do not use the word
profilewhen creating an entry in thecredentialsfile.
Each profile can specify different credentials and can also specify different
AWS Regions and output formats. When naming the profile in a
config file, include the prefix word
"profile", but do not include it in the
credentials file.
The following examples show a credentials and
config file with two profiles, region, and output specified. The
first [default] is used when you run a AWS CLI
command with no profile specified. The second is used when you run a AWS CLI command
with the --profile user1 parameter.
For more information and additional authorization and credential methods see, see Authenticating using IAM user credentials for the AWS CLI.
Section type: sso-session
The sso-session section of the config file is
used to group configuration variables for acquiring SSO access tokens, which can
then be used to acquire AWS credentials. The following settings are used:
-
(Required)
sso_start_url -
(Required)
sso_region
You define an sso-session section and associate it to a profile.
sso_region and sso_start_url must be set within the
sso-session section. Typically, sso_account_id and
sso_role_name must be set in the profile section so
that the SDK can request SSO credentials.
The following example configures the SDK to request SSO credentials and supports automated token refresh:
[profiledev] sso_session =my-ssosso_account_id =111122223333sso_role_name =SampleRole[sso-sessionmy-sso] sso_region =us-east-1sso_start_url =https://my-sso-portal.awsapps.com/start
This also allows sso-session configurations to be reused across
multiple profiles:
[profiledev] sso_session =my-ssosso_account_id =111122223333sso_role_name =SampleRole[profileprod] sso_session =my-ssosso_account_id =111122223333sso_role_name =SampleRole2[sso-sessionmy-sso] sso_region =us-east-1sso_start_url =https://my-sso-portal.awsapps.com/start
However, sso_account_id and sso_role_name aren't
required for all scenarios of SSO token configuration. If your application only uses
AWS services that support bearer authentication, then traditional AWS
credentials are not needed. Bearer authentication is an HTTP authentication scheme
that uses security tokens called bearer tokens. In this scenario,
sso_account_id and sso_role_name aren't required. See
the individual guide for your AWS service to determine if it supports bearer token
authorization.
Additionally, registration scopes can be configured as part of a
sso-session. Scope is a mechanism in OAuth 2.0 to limit an
application's access to a user's account. An application can request one or more
scopes, and the access token issued to the application will be limited to the scopes
granted. These scopes define the permissions requested to be authorized for the
registered OIDC client and access tokens retrieved by the client. The following
example sets sso_registration_scopes to provide access for listing
accounts/roles:
[sso-sessionmy-sso] sso_region =us-east-1sso_start_url =https://my-sso-portal.awsapps.com/startsso_registration_scopes =sso:account:access
The authentication token is cached to disk under the
~/.aws/sso/cache directory with a filename based on the
session name.
For more information on this configuration type, see Configuring IAM Identity Center authentication with the AWS CLI.
Section type: services
The services section is a group of settings that configures custom
endpoints for AWS service requests. A profile then is linked to a
services section.
[profiledev] services =my-services
The services section is separated into subsections by
<SERVICE> = lines, where <SERVICE> is the
AWS service identifier key. The AWS service identifier is based on the API
model’s serviceId by replacing all spaces with underscores and
lowercasing all letters. For a list of all service identifier keys to use in the
services section, see Using endpoints in the AWS CLI.
The service identifier key is followed by nested settings with each on its own line
and indented by two spaces.
The following example configures the endpoint to use for requests made to the
Amazon DynamoDB service in the my-services
section that is used in the dev profile. Any immediately
following lines that are indented are included in that subsection and apply to that
service.
[profiledev] services =my-services[servicesmy-services] dynamodb = endpoint_url =http://localhost:8000
For more information on service-specific endpoints, see Using endpoints in the AWS CLI.
If your profile has role-based credentials configured through a
source_profile parameter for IAM assume role functionality, the
SDK only uses service configurations for the specified profile. It does not use
profiles that are role chained to it. For example, using the following
shared config file:
[profileA] credential_source =Ec2InstanceMetadataendpoint_url =https://profile-a-endpoint.aws/[profileB] source_profile =Arole_arn =arn:aws:iam::123456789012:role/roleBservices =profileB[servicesprofileB] ec2 = endpoint_url =https://profile-b-ec2-endpoint.aws
If you use profile B and make a call in your code to Amazon EC2, the
endpoint resolves as https://profile-b-ec2-endpoint.aws. If your code
makes a request to any other service, the endpoint resolution will not follow any
custom logic. The endpoint does not resolve to the global endpoint defined in
profile A. For a global endpoint to take effect for profile
B, you would need to set endpoint_url directly within
profile B.
Where are configuration settings stored?
The AWS CLI stores sensitive credential information that you specify with aws
configure in a local file named credentials, in a folder
named in your home directory. The less sensitive
configuration options that you specify with .awsaws configure are stored in a
local file named config, also stored in the
folder in your home directory. .aws
Storing credentials in the config file
You can keep all of your profile settings in a single file as the AWS CLI can read
credentials from the config file. If there are credentials in
both files for a profile sharing the same name, the keys in the credentials file
take precedence. We suggest keeping credentials in the credentials
files. These files are also used by the various language software development kits
(SDKs). If you use one of the SDKs in addition to the AWS CLI, confirm if the
credentials should be stored in their own file.
Where you find your home directory location varies based on the operating system, but
is referred to using the environment variables %UserProfile% in Windows and
$HOME or ~ (tilde) in Unix-based systems. You can specify
a non-default location for the files by setting the AWS_CONFIG_FILE and
AWS_SHARED_CREDENTIALS_FILE environment variables to another local
path. See Configuring environment variables for the AWS CLI
for details.
When you use a shared profile that specifies an AWS Identity and Access Management (IAM) role, the
AWS CLI calls the AWS STS AssumeRole operation to retrieve temporary
credentials. These credentials are then stored (in
). Subsequent AWS CLI commands
use the cached temporary credentials until they expire, and at that point the AWS CLI
automatically refreshes the credentials.~/.aws/cli/cache
Using named profiles
If no profile is explicitly defined, the default profile is used.
To use a named profile, add the --profile
option to your command. The
following example lists all of your Amazon EC2 instances using the credentials and settings
defined in the profile-nameuser1 profile.
$aws ec2 describe-instances --profile user1
To use a named profile for multiple commands, you can avoid specifying the profile in
every command by setting the AWS_PROFILE environment variable as the
default profile. You can override this setting by using the --profile
parameter.
Set and view configuration settings using commands
There are several ways to view and set your configuration settings using commands.
aws configure-
Run this command to quickly set and view your credentials, Region, and output format. The following example shows sample values.
$aws configureAWS Access Key ID [None]:AWS Secret Access Key [None]:AKIAIOSFODNN7EXAMPLEDefault region name [None]:wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYDefault output format [None]:us-west-2json aws configure set-
You can set any credentials or configuration settings using
aws configure set. Specify the profile that you want to view or modify with the--profilesetting.For example, the following command sets the
regionin the profile namedinteg.$aws configure set regionus-west-2--profileintegTo remove a setting, manually delete the setting in your
configandcredentialsfiles in a text editor. aws configure get-
You can retrieve any credentials or configuration settings you've set using
aws configure get. Specify the profile that you want to view or modify with the--profilesetting.For example, the following command retrieves the
regionsetting in the profile namedinteg.$aws configure getregion--profileintegus-west-2If the output is empty, the setting is not explicitly set and uses the default value.
aws configure import-
Import
CSVcredentials generated from the IAM web console. This is not for credentials generated from IAM Identity Center; customers who use IAM Identity Center should use aws configure sso. A CSV file is imported with the profile name matching the username. The CSV file must contain the following headers.-
User Name
-
Access key ID
-
Secret access key
Note
During initial key pair creation, once you close the Download .csv file dialog box, you cannot access your secret access key after you close the dialog box. If you need a
.csvfile, you'll need to create one yourself with the required headers and your stored key pair information. If you do not have access to your key pair information, you need to create a new key pair.$aws configure import --csvfile://credentials.csv -
aws configure list-
To list configuration data, use the
aws configure listcommand. This command lists the profile, access key, secret key, and region configuration information used for the specified profile. For each configuration item, it shows the value, where the configuration value was retrieved, and the configuration variable name.For example, if you provide the AWS Region in an environment variable, this command shows you the name of the region you've configured, that this value came from an environment variable, and the name of the environment variable.
For temporary credential methods such as roles and IAM Identity Center, this command displays the temporarily cached access key and secret access key is displayed.
$aws configure listNAME : VALUE : TYPE : LOCATION profile : <not set> : None : None access_key : ****************ABCD : shared-credentials-file : secret_key : ****************ABCD : shared-credentials-file : region : us-west-2 : env : AWS_DEFAULT_REGION aws configure list-profiles-
To list all your profile names, use the
aws configure list-profilescommand.$aws configure list-profilesdefault test aws configure mfa-login-
Run this command to configure a new profile to use with multi-factor authentication (MFA) and your IAM user credentials in the specified profile. If no profile is specified, the MFA is based on the
defaultprofile. If no default profile is configured, themfa-logincommand prompts you for you AWS credentials before asking for your MFA information. The following command example uses your default configuration and creates an MFA profile.$aws configure mfa-loginMFA serial number or ARN:arn:aws:iam::123456789012:mfa/MFADeviceNameMFA token code:123456Profile to update [session-MFADeviceName]: Temporary credentials written to profile 'session-MFADeviceName' Credentials will expire at 2023-05-19 18:06:10 UTC To use these credentials, specify --profile session-MFADeviceName when running AWS CLI commandsTo update an existing profile, use the
--update-profileparameter.$aws configure mfa-login --profilemyprofile--update-profilemfaprofileMFA token code:123456Temporary credentials written to profile 'mfaprofile' Credentials will expire at 2023-05-19 18:06:10 UTC To use these credentials, specify --profile mfaprofile when running AWS CLI commandsThis command currently supports only hardware or software based one-time password (OTP) authenticators. Passkeys and U2F devices are not currently supported with this command.
For more information on using MFA with IAM, see AWS Multi-factor authentication in IAM in the AWS Identity and Access Management User Guide.
aws configure sso-
Run this command to quickly set and view your AWS IAM Identity Center credentials, Region, and output format. The following example shows sample values.
$aws configure ssoSSO session name (Recommended):my-ssoSSO start URL [None]:https://my-sso-portal.awsapps.com/startSSO region [None]:us-east-1SSO registration scopes [None]:sso:account:access aws configure sso-session-
Run this command to quickly set and view your AWS IAM Identity Center credentials, Region, and output format in the
sso-sessionsection of thecredentialsandconfigfiles. The following example shows sample values.$aws configure sso-sessionSSO session name:my-ssoSSO start URL [None]:https://my-sso-portal.awsapps.com/startSSO region [None]:us-east-1SSO registration scopes [None]:sso:account:access aws configure export-credentials-
Run this command to export currently set credentials in the specified format. By default, the command exports the default credentials in the
processformat, which is a JSON format supported by the AWS SDKs and Tools credential format.$aws configure export-credentials{ "Version": 1, "AccessKeyId": "AKIAIOSFODNN7EXAMPLE", "SecretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" }To export a specific profile and format, use the
--profileand--formatoptions. The format options are as follows:-
(default)
process‐ The JSON format supported by the AWS SDKs and Toolscredential_processconfiguration. -
env‐ Environment variables in exported shell format. -
env-no-export‐ Non-exported environment variables in shell format. -
powershell‐ Environment variables in PowerShell format. -
windows-cmd‐ Environment variables in Windows Command Line format.
The following example exports the
user1profile to an exported shell format.$aws configure export-credentials--profile user1 --format envexport AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -
Setting new configuration and credentials command examples
The following examples show configuring a default profile with credentials, region, and output specified for different authentication methods.
Supported config file settings
The following settings are supported in the config file. The
values listed in the specified (or default) profile are used unless they are overridden
by the presence of an environment variable with the same name, or a command line option
with the same name. For more information on what order settings take precendence, see
Configuring settings for the AWS CLI
Global settings
-
account_id_endpoint_mode -
Specifies whether to use AWS account-based endpoint IDs for calls to supported AWS services. For more information on account-based endpoints, see Account-based endpoints.
This setting can be set to the following:
-
(default)
preferred– The endpoint should include account ID if available. -
-