Function aws_config::profile::load

source ·
pub async fn load(
    fs: &Fs,
    env: &Env,
    profile_files: &EnvConfigFiles,
    selected_profile_override: Option<Cow<'static, str>>,
) -> Result<ProfileSet, ProfileFileLoadError>
Expand description

Read & parse AWS config files

Loads AWS config file from the filesystem, parses them, and converts them into a ProfileSet.

Although the basic behavior is straightforward, there are number of nuances to maintain backwards compatibility with other SDKs enumerated below.

§Location of Profile Files

  • The location of the config file will be loaded from the AWS_CONFIG_FILE environment variable with a fallback to ~/.aws/config
  • The location of the credentials file will be loaded from the AWS_SHARED_CREDENTIALS_FILE environment variable with a fallback to ~/.aws/credentials

The location of these files can also be customized programmatically using ProfileFiles.

§Home directory resolution

Home directory resolution is implemented to match the behavior of the CLI & Python. ~ is only used for home directory resolution when it:

  • Starts the path
  • Is followed immediately by / or a platform specific separator. (On windows, ~/ and ~\ both resolve to the home directory.

When determining the home directory, the following environment variables are checked:

  • HOME on all platforms
  • USERPROFILE on Windows
  • The concatenation of HOMEDRIVE and HOMEPATH on Windows ($HOMEDRIVE$HOMEPATH)

§Profile file syntax

Profile files have a form similar to .ini but with a several edge cases. These behaviors exist to match existing parser implementations, ensuring consistent behavior across AWS SDKs. These cases fully enumerated in test-data/profile-parser-tests.json.

§The config file ~/.aws/config

# ~/.aws/config
[profile default]
key = value

# profiles must begin with `profile`
[profile other]
key = value2

§The credentials file ~/.aws/credentials

The main difference is that in ~/.aws/credentials, profiles MUST NOT be prefixed with profile:

[default]
aws_access_key_id = 123

[other]
aws_access_key_id = 456