View a markdown version of this page

Configuration and credential file settings in the AWS CLI - AWS Command Line Interface

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.

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 user1], and [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] [profile user1]

  • Credentials file: [default] [user1]

    Do not use the word profile when creating an entry in the credentials file.

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.

IAM Identity Center (SSO)

This example is for AWS IAM Identity Center. For more information, see Configuring IAM Identity Center authentication with the AWS CLI.

Credentials file

The credentials file is not used for this authentication method.

Config file

[default] sso_session = my-sso sso_account_id = 111122223333 sso_role_name = readOnly region = us-west-2 output = text [profile user1] sso_session = my-sso sso_account_id = 444455556666 sso_role_name = readOnly region = us-east-1 output = json [sso-session my-sso] sso_region = us-east-1 sso_start_url = https://my-sso-portal.awsapps.com/start sso_registration_scopes = sso:account:access
IAM Identity Center (Legacy SSO)

This example is for the legacy method of AWS IAM Identity Center. For more information, see Configuring IAM Identity Center authentication with the AWS CLI.

Credentials file

The credentials file is not used for this authentication method.

Config file

[default] sso_start_url = https://my-sso-portal.awsapps.com/start sso_region = us-east-1 sso_account_id = 111122223333 sso_role_name = readOnly region = us-west-2 output = text [profile user1] sso_start_url = https://my-sso-portal.awsapps.com/start sso_region = us-east-1 sso_account_id = 444455556666 sso_role_name = readOnly region = us-east-1 output = json
Short-term credentials

This example is for the short-term credentials from AWS Identity and Access Management. For more information, see Authenticating with short-term credentials for the AWS CLI.

Credentials file

[default] aws_access_key_id=ASIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY aws_session_token = IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZVERYLONGSTRINGEXAMPLE [user1] aws_access_key_id=ASIAI44QH8DHBEXAMPLE aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY aws_session_token = fcZib3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZVERYLONGSTRINGEXAMPLE

Config file

[default] region=us-west-2 output=json [profile user1] region=us-east-1 output=text
IAM role

This example is for assuming an IAM role. Profiles that use IAM roles pull credentials from another profile, and then apply IAM role permissions. In the following examples, default is the source profile for credentials and user1 borrows the same credentials then assumes a new role. For more information, see Using an IAM role in the AWS CLI.

Credentials file

The credentials file depends on what authentication your source profile uses. For the following example, the source profile uses short-term credentials.

[default] aws_access_key_id=ASIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY aws_session_token = IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZVERYLONGSTRINGEXAMPLE

Config file

[default] region=us-west-2 output=json [profile user1] role_arn=arn:aws:iam::777788889999:role/user1role source_profile=default role_session_name=session_user1 region=us-east-1 output=text
Amazon EC2 instance metadata credentials

This example is for the credentials obtained from the hosting Amazon EC2 instance metadata. For more information, see Using Amazon EC2 instance metadata as credentials in the AWS CLI.

Credentials file

The credentials file is not used for this authentication method.

Config file

[default] role_arn=arn:aws:iam::123456789012:role/defaultrole credential_source=Ec2InstanceMetadata region=us-west-2 output=json [profile user1] role_arn=arn:aws:iam::777788889999:role/user1role credential_source=Ec2InstanceMetadata region=us-east-1 output=text
Long-term credentials
Warning

To avoid security risks, don't use IAM users for authentication when developing purpose-built software or working with real data. Instead, use federation with an identity provider such as AWS IAM Identity Center.

This example is for the long-term credentials from AWS Identity and Access Management. For more information, see Authenticating using IAM user credentials for the AWS CLI.

Credentials file

[default] aws_access_key_id=AKIAIOSFODNN7EXAMPLE aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY [user1] aws_access_key_id=AKIAI44QH8DHBEXAMPLE aws_secret_access_key=je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY

Config file

[default] region=us-west-2 output=json [profile user1] region=us-east-1 output=text

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:

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:

[profile dev] sso_session = my-sso sso_account_id = 111122223333 sso_role_name = SampleRole [sso-session my-sso] sso_region = us-east-1 sso_start_url = https://my-sso-portal.awsapps.com/start

This also allows sso-session configurations to be reused across multiple profiles:

[profile dev] sso_session = my-sso sso_account_id = 111122223333 sso_role_name = SampleRole [profile prod] sso_session = my-sso sso_account_id = 111122223333 sso_role_name = SampleRole2 [sso-session my-sso] sso_region = us-east-1 sso_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-session my-sso] sso_region = us-east-1 sso_start_url = https://my-sso-portal.awsapps.com/start sso_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.

[profile dev] 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.

[profile dev] services = my-services [services my-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:

[profile A] credential_source = Ec2InstanceMetadata endpoint_url = https://profile-a-endpoint.aws/ [profile B] source_profile = A role_arn = arn:aws:iam::123456789012:role/roleB services = profileB [services profileB] 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 .aws in your home directory. The less sensitive configuration options that you specify with aws configure are stored in a local file named config, also stored in the .aws folder in your home directory.

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 ~/.aws/cli/cache). Subsequent AWS CLI commands use the cached temporary credentials until they expire, and at that point the AWS CLI automatically refreshes the credentials.

Using named profiles

If no profile is explicitly defined, the default profile is used.

To use a named profile, add the --profile profile-name option to your command. The following example lists all of your Amazon EC2 instances using the credentials and settings defined in the user1 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.

Linux or macOS
$ export AWS_PROFILE=user1
Windows
C:\> setx AWS_PROFILE user1

Using set to set an environment variable changes the value used until the end of the current command prompt session, or until you set the variable to a different value.

Using setx to set an environment variable changes the value in all command shells that you create after running the command. It does not affect any command shell that is already running at the time you run the command. Close and restart the command shell to see the effects of the change.

Setting the environment variable changes the default profile until the end of your shell session, or until you set the variable to a different value. You can make environment variables persistent across future sessions by putting them in your shell's startup script. For more information, see Configuring environment variables for the AWS CLI.

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 configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: json
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 --profile setting.

For example, the following command sets the region in the profile named integ.

$ aws configure set region us-west-2 --profile integ

To remove a setting, manually delete the setting in your config and credentials files 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 --profile setting.

For example, the following command retrieves the region setting in the profile named integ.

$ aws configure get region --profile integ us-west-2

If the output is empty, the setting is not explicitly set and uses the default value.

aws configure import

Import CSV credentials 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 .csv file, 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 --csv file://credentials.csv
aws configure list

To list configuration data, use the aws configure list command. 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 list NAME : 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-profiles command.

$ aws configure list-profiles default 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 default profile. If no default profile is configured, the mfa-login command 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-login MFA serial number or ARN: arn:aws:iam::123456789012:mfa/MFADeviceName MFA token code: 123456 Profile 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 commands

To update an existing profile, use the --update-profile parameter.

$ aws configure mfa-login --profile myprofile --update-profile mfaprofile MFA token code: 123456 Temporary 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 commands

This 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 sso SSO session name (Recommended): my-sso SSO start URL [None]: https://my-sso-portal.awsapps.com/start SSO region [None]: us-east-1 SSO 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-session section of the credentials and config files. The following example shows sample values.

$ aws configure sso-session SSO session name: my-sso SSO start URL [None]: https://my-sso-portal.awsapps.com/start SSO region [None]: us-east-1 SSO 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 process format, 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 --profile and --format options. The format options are as follows:

  • (default)process ‐ The JSON format supported by the AWS SDKs and Tools credential_process configuration.

  • 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 user1 profile to an exported shell format.

$ aws configure export-credentials --profile user1 --format env export 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.

Console sessions as short-term credentials

This example lets you use your existing console credentials with the aws login command. This sign in method can be used with root credentials created during initial account set up, an IAM user, or a federated identity from your identity provider. For more information, see Login for AWS local development using console credentials.

$ aws login No AWS region has been configured. The AWS region is the geographic location of your AWS resources. If you've used AWS before and already have resources in your account, tell us which region they were created in. If you haven't created resources in your account before, you can pick the region closest to you: https://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html. You are able to change the region in the CLI at any time with the command `aws configure set region NEW_REGION`. AWS Region [us-east-1]: us-east-1 Attempting to open the login page for `us-east-1` in your default browser. If the browser does not open, use the following URL to complete your login: https://us-east-1.signin.aws.amazon.com/v1/authorize<abbreviated> If you cannot connect to this URL, make sure that you have specified a valid region. Waiting for login... Logged in with role `arn:aws:sts::012345678910:user/iam-user`, and configured profile `default` to use `us-east-1`. This session will expire on October 14, 2025 at 2:04 PST. After this time, you can renew your session with `aws login`.
IAM Identity Center (SSO)

This example is for AWS IAM Identity Center using the aws configure sso wizard. For more information, see Configuring IAM Identity Center authentication with the AWS CLI.

$ aws configure sso SSO session name (Recommended): my-sso SSO start URL [None]: https://my-sso-portal.awsapps.com/start SSO region [None]:us-east-1 Attempting to automatically open the SSO authorization page in your default browser. There are 2 AWS accounts available to you. > DeveloperAccount, developer-account-admin@example.com (111122223333) ProductionAccount, production-account-admin@example.com (444455556666) Using the account ID 111122223333 There are 2 roles available to you. > ReadOnly FullAccess Using the role name "ReadOnly" CLI default client Region [None]: us-west-2 CLI default output format [None]: json CLI profile name [123456789011_ReadOnly]: user1
IAM Identity Center (Legacy SSO)

This example is for the legacy method of AWS IAM Identity Center using the aws configure sso wizard. To use the legacy SSO, leave the session name blank. For more information, see Configuring IAM Identity Center authentication with the AWS CLI.

$ aws configure sso SSO session name (Recommended): SSO start URL [None]: https://my-sso-portal.awsapps.com/start SSO region [None]:us-east-1 SSO authorization page has automatically been opened in your default browser. Follow the instructions in the browser to complete this authorization request. There are 2 AWS accounts available to you. > DeveloperAccount, developer-account-admin@example.com (111122223333) ProductionAccount, production-account-admin@example.com (444455556666) Using the account ID 111122223333 There are 2 roles available to you. > ReadOnly FullAccess Using the role name "ReadOnly" CLI default client Region [None]: us-west-2 CLI default output format [None]: json CLI profile name [123456789011_ReadOnly]: user1
Short-term credentials

This example is for the short-term credentials from AWS Identity and Access Management. The aws configure wizard is used to set initial values and then the aws configure set command assigns the last value needed. For more information, see Authenticating with short-term credentials for the AWS CLI.

$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: json $ aws configure set aws_session_token fcZib3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZ2luX2IQoJb3JpZVERYLONGSTRINGEXAMPLE
IAM role

This example is for assuming an IAM role. Profiles that use IAM roles pull credentials from another profile, and then apply IAM role permissions. In the following examples, default is the source profile for credentials and user1 borrows the same credentials then assumes a new role. There is no wizard for this process, therefore each value is set using the aws configure set command. For more information, see Using an IAM role in the AWS CLI.

$ aws configure set role_arn arn:aws:iam::123456789012:role/defaultrole $ aws configure set source_profile default $ aws configure set role_session_name session_user1 $ aws configure set region us-west-2 $ aws configure set output json
Amazon EC2 instance metadata credentials

This example is for the credentials obtained from the hosting Amazon EC2 instance metadata. There is no wizard for this process, therefore each value is set using the aws configure set command. For more information, see Using Amazon EC2 instance metadata as credentials in the AWS CLI.

$ aws configure set role_arn arn:aws:iam::123456789012:role/defaultrole $ aws configure set credential_source Ec2InstanceMetadata $ aws configure set region us-west-2 $ aws configure set output json
Long-term credentials
Warning

To avoid security risks, don't use IAM users for authentication when developing purpose-built software or working with real data. Instead, use federation with an identity provider such as AWS IAM Identity Center.

This example is for the long-term credentials from AWS Identity and Access Management. For more information, see Authenticating using IAM user credentials for the AWS CLI.

$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: json

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.