Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @aws-sdk/shared-ini-file-loader

@aws-sdk/shared-ini-file-loader

NPM version NPM downloads

AWS Shared Configuration File Loader

This module provides a function that reads from AWS SDK configuration files and returns a promise that will resolve with a hash of the parsed contents of the AWS credentials file and of the AWS config file. Given the sample files below, the promise returned by loadSharedConfigFiles would resolve with:

{
  configFile: {
    'default': {
      aws_access_key_id: 'foo',
      aws_secret_access_key: 'bar',
    },
    dev: {
      aws_access_key_id: 'foo1',
      aws_secret_access_key: 'bar1',
    },
    prod: {
      aws_access_key_id: 'foo2',
      aws_secret_access_key: 'bar2',
    },
    'testing host': {
      aws_access_key_id: 'foo4',
      aws_secret_access_key: 'bar4',
    }
  },
  credentialsFile: {
    'default': {
      aws_access_key_id: 'foo',
      aws_secret_access_key: 'bar',
    },
    dev: {
      aws_access_key_id: 'foo1',
      aws_secret_access_key: 'bar1',
    },
    prod: {
      aws_access_key_id: 'foo2',
      aws_secret_access_key: 'bar2',
    }
  },
}

If a file is not found, its key (configFile or credentialsFile) will instead have a value of an empty object.

Supported configuration

You may customize how the files are loaded by providing an options hash to the loadSharedConfigFiles function. The following options are supported:

  • filepath - The path to the shared credentials file. If not specified, the provider will use the value in the AWS_SHARED_CREDENTIALS_FILE environment variable or a default of ~/.aws/credentials.
  • configFilepath - The path to the shared config file. If not specified, the provider will use the value in the AWS_CONFIG_FILE environment variable or a default of ~/.aws/config.

Sample files

~/.aws/credentials

[default]
aws_access_key_id=foo
aws_secret_access_key=bar

[dev]
aws_access_key_id=foo2
aws_secret_access_key=bar2

[prod]
aws_access_key_id=foo3
aws_secret_access_key=bar3

~/.aws/config

[default]
aws_access_key_id=foo
aws_secret_access_key=bar

[profile dev]
aws_access_key_id=foo2
aws_secret_access_key=bar2

[profile prod]
aws_access_key_id=foo3
aws_secret_access_key=bar3

[profile "testing host"]
aws_access_key_id=foo4
aws_secret_access_key=bar4

Index

References

DEFAULT_PROFILE

Re-exports DEFAULT_PROFILE

ENV_PROFILE

Re-exports ENV_PROFILE

ParsedIniData

Re-exports ParsedIniData

Profile

Re-exports Profile

SSOToken

Re-exports SSOToken

SharedConfigFiles

Re-exports SharedConfigFiles

SharedConfigInit

Re-exports SharedConfigInit

SourceProfileInit

Re-exports SourceProfileInit

getHomeDir

Re-exports getHomeDir

getProfileName

Re-exports getProfileName

getSSOTokenFilepath

Re-exports getSSOTokenFilepath

getSSOTokenFromFile

Re-exports getSSOTokenFromFile

loadSharedConfigFiles

Re-exports loadSharedConfigFiles

parseKnownFiles

Re-exports parseKnownFiles

Type aliases

ParsedIniData

ParsedIniData: __ParsedIniData
deprecated

Use ParsedIniData from "@aws-sdk/types" instead

Profile

Profile: __Profile
deprecated

Use Profile from "@aws-sdk/types" instead

SharedConfigFiles

SharedConfigFiles: __SharedConfigFiles
deprecated

Use SharedConfigFiles from "@aws-sdk/types" instead

Variables

Const DEFAULT_PROFILE

DEFAULT_PROFILE: "default" = "default"

Const ENV_CONFIG_PATH

ENV_CONFIG_PATH: "AWS_CONFIG_FILE" = "AWS_CONFIG_FILE"

Const ENV_CREDENTIALS_PATH

ENV_CREDENTIALS_PATH: "AWS_SHARED_CREDENTIALS_FILE" = "AWS_SHARED_CREDENTIALS_FILE"

Const ENV_PROFILE

ENV_PROFILE: "AWS_PROFILE" = "AWS_PROFILE"

Const filePromisesHash

filePromisesHash: Record<string, Promise<string>>

Const profileKeyRegex

profileKeyRegex: RegExp = /^profile\s(["'])?([^\1]+)\1$/

Const profileNameBlockList

profileNameBlockList: string[] = ["__proto__", "profile __proto__"]

readFile

readFile: readFile

readFile

readFile: readFile

Functions

Const getConfigFilepath

  • getConfigFilepath(): string

Const getCredentialsFilepath

  • getCredentialsFilepath(): string

Const getHomeDir

  • getHomeDir(): string

Const getProfileData

Const getProfileName

  • getProfileName(init: { profile?: string }): string

Const getSSOTokenFilepath

  • getSSOTokenFilepath(ssoStartUrl: string): string

Const getSSOTokenFromFile

  • getSSOTokenFromFile(ssoStartUrl: string): Promise<SSOToken>

Const loadSharedConfigFiles

Const parseIni

Const parseKnownFiles

Const slurpFile

  • slurpFile(path: string): Promise<string>

Const swallowError

  • swallowError(): {}