{"name":"@aws-sdk/credential-providers","version":"3.1072.0","keywords":["aws","credentials"],"author":{"url":"https://aws.amazon.com/sdk-for-javascript/","name":"AWS SDK for JavaScript Team"},"license":"Apache-2.0","_id":"@aws-sdk/credential-providers@3.1072.0","maintainers":[{"name":"amzn-oss","email":"osa-3p@amazon.com"},{"name":"aws-sdk-bot","email":"aws-sdk-js-automation@amazon.com"}],"homepage":"https://github.com/aws/aws-sdk-js-v3/tree/main/packages/credential-providers","bugs":{"url":"https://github.com/aws/aws-sdk-js-v3/issues"},"dist":{"shasum":"34f1b32fd9f1aa9cc29ed56a276b67c7eb0c7643","tarball":"http://registry-npm.ywwl.com/@aws-sdk/credential-providers/download/@aws-sdk/credential-providers-3.1072.0.tgz","fileCount":79,"integrity":"sha512-TapaSwjVRVOV/1yEqlNRg6Co+YFnUBhYBlYZomHaY5FfbrsrtFueCBy0cDDrvr9s5wVIUkYLdsfiXeitatHfJg==","signatures":[{"sig":"MEYCIQCbrsd+fBtg5B4+04H5OwehZWQjC1AOVeCZle8KvgxSFwIhAK4tQ6d+48KYXS7zf/hwbVplWBIx0l61shJFe5eFg0OI","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":116884,"size":27153,"noattachment":false,"key":"/@aws-sdk/credential-providers/-/@aws-sdk/credential-providers-3.1072.0.tgz"},"main":"./dist-cjs/index.js","types":"./dist-types/index.d.ts","module":"./dist-es/index.js","browser":{"./dist-es/index":"./dist-es/index.browser","./dist-es/fromTemporaryCredentials":"./dist-es/fromTemporaryCredentials.browser"},"engines":{"node":">=20.0.0"},"scripts":{"test":"yarn g:vitest run","build":"concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs","clean":"premove dist-cjs dist-es dist-types","build:es":"premove dist-es && tsc -p tsconfig.es.json","build:cjs":"node ../../scripts/compilation/inline","test:watch":"yarn g:vitest watch","build:types":"premove dist-types && tsc -p tsconfig.types.json","extract:docs":"api-extractor run --local","test:integration":"yarn g:vitest run -c vitest.config.integ.mts","build:include:deps":"yarn g:turbo run build -F=\"$npm_package_name\"","build:types:downlevel":"downlevel-dts dist-types dist-types/ts3.4","test:integration:watch":"yarn g:vitest watch -c vitest.config.integ.mts"},"_npmUser":{"name":"aws-sdk-bot","email":"aws-sdk-js-automation@amazon.com"},"repository":{"url":"git+https://github.com/aws/aws-sdk-js-v3.git","type":"git","directory":"packages/credential-providers"},"_npmVersion":"11.7.0","description":"A collection of credential providers, without requiring service clients like STS, Cognito","directories":{},"sideEffects":false,"_nodeVersion":"24.14.0","dependencies":{"tslib":"^2.6.2","@smithy/core":"^3.24.6","@aws-sdk/core":"^3.974.22","@smithy/types":"^4.14.3","@aws-sdk/types":"^3.973.13","@aws-sdk/nested-clients":"^3.997.22","@aws-sdk/client-cognito-identity":"3.1072.0","@aws-sdk/credential-provider-env":"^3.972.48","@aws-sdk/credential-provider-ini":"^3.972.55","@aws-sdk/credential-provider-sso":"^3.972.54","@smithy/credential-provider-imds":"^4.3.7","@aws-sdk/credential-provider-http":"^3.972.50","@aws-sdk/credential-provider-node":"^3.972.57","@aws-sdk/credential-provider-login":"^3.972.54","@aws-sdk/credential-provider-process":"^3.972.48","@aws-sdk/credential-provider-web-identity":"^3.972.54","@aws-sdk/credential-provider-cognito-identity":"^3.972.47"},"react-native":{"./dist-es/index":"./dist-es/index.browser","./dist-cjs/index":"./dist-cjs/index.browser","./dist-es/fromTemporaryCredentials":"./dist-es/fromTemporaryCredentials.browser","./dist-cjs/fromTemporaryCredentials":"./dist-cjs/fromTemporaryCredentials.browser"},"typesVersions":{"<4.5":{"dist-types/*":["dist-types/ts3.4/*"]}},"_hasShrinkwrap":false,"devDependencies":{"premove":"4.0.0","typescript":"~5.8.3","@types/node":"^20.14.8","concurrently":"7.0.0","downlevel-dts":"0.10.1","@tsconfig/recommended":"1.0.1"},"_npmOperationalInternal":{"tmp":"tmp/credential-providers_3.1072.0_1781808484420_0.2574202354570554","host":"s3://npm-registry-packages-npm-production"},"readme":"# @aws-sdk/credential-providers\n\n[![NPM version](https://img.shields.io/npm/v/@aws-sdk/credential-providers/latest.svg)](https://www.npmjs.com/package/@aws-sdk/credential-providers)\n[![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/credential-providers.svg)](https://www.npmjs.com/package/@aws-sdk/credential-providers)\n\nA collection of all credential providers.\n\n# Table of Contents\n\n- [Terminology](#terminology)\n  - [Credentials Provider](#credentials-provider)\n  - [Outer and inner clients](#outer-and-inner-clients)\n- [Resolving AWS Region in credential providers (e.g. STS region)](#resolving-aws-region-in-credential-providers-eg-sts-region)\n- [From Cognito Identity](#fromcognitoidentity)\n- [From Cognito Identity Pool](#fromcognitoidentitypool)\n- [From Temporary Credentials](#fromtemporarycredentials)\n- [From Web Token](#fromwebtoken)\n  - [Examples](#examples)\n- [From Token File](#fromtokenfile)\n- [From Instance and Container Metadata Service](#fromcontainermetadata-and-frominstancemetadata)\n- [From HTTP(S)](#fromhttp)\n- [From Shared INI files](#fromini)\n  - [Sample Files](#sample-files)\n- [From Environmental Variables](#fromenv)\n- [From Credential Process](#fromprocess)\n  - [Sample files](#sample-files-1)\n- [From Single Sign-On Service](#fromsso)\n  - [Supported Configuration](#supported-configuration)\n  - [SSO login with AWS CLI](#sso-login-with-the-aws-cli)\n  - [Sample Files](#sample-files-2)\n- [From Login Credentials](#fromLoginCredentials)\n  - [Login with AWS CLI](#login-with-aws-cli)\n  - [Sample Files](#sample-files-3)\n- [From Node.js default credentials provider chain](#fromnodeproviderchain)\n- [Creating a custom credentials chain](#createcredentialchain)\n\n## Terminology\n\n#### Credentials Provider\n\nAn `AwsCredentialIdentityProvider` is any function that matches the signature:\n\n```ts\n() =>\n  Promise<{\n    /**\n     * AWS access key ID\n     */\n    readonly accessKeyId: string;\n    /**\n     * AWS secret access key\n     */\n    readonly secretAccessKey: string;\n    /**\n     * A security or session token to use with these credentials. Usually\n     * present for temporary credentials.\n     */\n    readonly sessionToken?: string;\n    /**\n     * A `Date` when the identity or credential will no longer be accepted.\n     * You can set or override this on the client side to force a refresh\n     * call of the function supplying the credentials when 5 minutes remain.\n     */\n    readonly expiration?: Date;\n  }>;\n```\n\nThat is, an async function which returns an object containing AWS credentials.\n\nWhether you write your own such function or use one of the providers from this package, when used in\nconjunction with an AWS SDK Client, the client will cache the resulting credentials\nuntil there is less than 5 minutes remaining to their expiration, at which point the\nfunction will be called again, and the new credentials cached.\n\nThis is designed to minimize the number of credential requests. Each client\ninstance has a separate cache of credentials, so if you want to share credential caching\nbetween clients, you'll need to implement your own cache outside the SDK.\n\n#### Outer and inner clients\n\nA \"parent/outer/upper/caller\" (position), or \"data\" (purpose) client refers\nto a client being initialized explicitly by the SDK user.\n\nAn \"inner\" (position), or \"credentials\" (purpose) client\nrefers to a client being initialized by the SDK in the course\nof retrieving credentials. Several AWS SDK credentials providers\nmake use of inner clients such as Cognito, SSO, STS, and SSO-OIDC.\n\n```ts\n// Example: outer client and inner client\nconst s3 = new S3Client({\n  credentials: fromIni(),\n});\n```\n\nIn the above example, `S3Client` is the outer client, and\nif the `fromIni` credentials provider uses STS::AssumeRole, the\n`STSClient` initialized by the SDK is the inner client.\n\n## Resolving AWS Region in credential providers (e.g. STS region)\n\nWhen a credential provider uses an SDK client to retrieve credentials, commonly STS, the\ncontrol of the STS region follows this logic:\n\n```js\nimport { fromIni } from \"@aws-sdk/credential-providers\";\n\n/*\n# AWS config file contents\n[profile default]\nregion = profile-region\nrole_arn = ROLE_ARN\nsource_profile = assume\n\n[profile assume]\n...\n */\n\nprocess.env.AWS_REGION = \"env-region\";\n\nconst provider = fromIni({\n  clientConfig: {\n    region: \"credential-provider-config-region\",\n  },\n});\n\nconst client = new SDKClient({\n  region: \"context-client-region\",\n  credentials: provider,\n});\n\nconst fallbackRegion = \"us-east-1\";\n```\n\nAs shown above, there are many sources of region information. The priority order is:\n\n1. `credential-provider-config-region` - given in code to the credential provider itself.\n2. `profile-region` **\\*** - if credential provider is resolving credentials from the config file, the config file's\n   region takes precedence in this case over AWS_REGION env.\n3. `context-client-region` - the region resolved by an SDK client using the credential provider.\n4. `env-region` - AWS_REGION environment variable.\n5. `profile-region` **\\*** - if credential provider is not resolving credentials from the config file, the config file's\n   region is lower priority than AWS_REGION env.\n6. `us-east-1` (fallback) - this is a legacy fallback value. It's more likely that the client will fail to execute any\n   operation if none of the other region sources were set.\n\nThis differs from _direct_ instantiation of the STSClient, which follows this order, which is the same for all clients:\n\n```js\nimport { STSClient } from \"@aws-sdk/client-sts\";\n/*\n# AWS config file contents\n[profile default]\nregion = profile-region\n */\n\nprocess.env.AWS_REGION = \"env-region\";\n\nconst client = new STSClient({\n  region: \"client-region\",\n});\n```\n\n1. `client-region`\n2. `env-region`\n3. `profile-region` (config file)\n4. thrown error (no us-east-1 fallback)\n\n# Credential providers\n\n## `fromCognitoIdentity()`\n\n- Uses `@aws-sdk/client-cognito-identity`\n- Available in browsers & native apps\n\nThe function `fromCognitoIdentity()` returns a credentials provider that retrieves credentials for\nthe provided identity ID. See [GetCredentialsForIdentity API][getcredentialsforidentity_api]\nfor more information.\n\n```javascript\nimport { fromCognitoIdentity } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  region,\n  credentials: fromCognitoIdentity({\n    // Required. The unique identifier for the identity against which credentials\n    // will be issued.\n    identityId: \"us-east-1:128d0a74-c82f-4553-916d-90053example\",\n    // Optional. The ARN of the role to be assumed when multiple roles were received in the token\n    // from the identity provider.\n    customRoleArn: \"arn:aws:iam::1234567890:role/MYAPP-CognitoIdentity\",\n    // Optional. A set of name-value pairs that map provider names to provider tokens.\n    // Required when using identities associated with external identity providers such as Facebook.\n    logins: {\n      \"graph.facebook.com\": \"FBTOKEN\",\n      \"www.amazon.com\": \"AMAZONTOKEN\",\n      \"accounts.google.com\": \"GOOGLETOKEN\",\n      \"api.twitter.com\": \"TWITTERTOKEN'\",\n      \"www.digits.com\": \"DIGITSTOKEN\",\n    },\n    // Optional overrides. This is passed to an inner Cognito client\n    // instantiated to resolve the credentials. Region and profile\n    // are inherited from the upper client if present unless overridden.\n    clientConfig: {},\n  }),\n});\n```\n\n## `fromCognitoIdentityPool()`\n\n- Uses `@aws-sdk/client-cognito-identity`\n- Available in browsers & native apps\n\nThe function `fromCognitoIdentityPool()` returns `AwsCredentialIdentityProvider` that calls [GetId API][getid_api]\nto obtain an `identityId`, then generates temporary AWS credentials with\n[GetCredentialsForIdentity API][getcredentialsforidentity_api], see\n[`fromCognitoIdentity()`](#fromcognitoidentity).\n\nResults from `GetId` are cached internally, but results from `GetCredentialsForIdentity` are not.\n\n```javascript\nimport { fromCognitoIdentityPool } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  region,\n  credentials: fromCognitoIdentityPool({\n    // Required. The unique identifier for the identity pool from which an identity should be\n    // retrieved or generated.\n    identityPoolId: \"us-east-1:1699ebc0-7900-4099-b910-2df94f52a030\",\n    // Optional. A standard AWS account ID (9+ digits)\n    accountId: \"123456789\",\n    // Optional. A cache in which to store resolved Cognito IdentityIds.\n    cache: custom_storage,\n    // Optional. A unique identifier for the user used to cache Cognito IdentityIds on a per-user\n    // basis.\n    userIdentifier: \"user_0\",\n    // Optional. The ARN of the role to be assumed when multiple roles were received in the token\n    // from the identity provider.\n    customRoleArn: \"arn:aws:iam::1234567890:role/MYAPP-CognitoIdentity\",\n    // Optional. A set of name-value pairs that map provider names to provider tokens.\n    // Required when using identities associated with external identity providers such as Facebook.\n    logins: {\n      \"graph.facebook.com\": \"FBTOKEN\",\n      \"www.amazon.com\": \"AMAZONTOKEN\",\n      \"accounts.google.com\": \"GOOGLETOKEN\",\n      \"api.twitter.com\": \"TWITTERTOKEN\",\n      \"www.digits.com\": \"DIGITSTOKEN\",\n    },\n    // Optional overrides. This is passed to an inner Cognito client\n    // instantiated to resolve the credentials. Region and profile\n    // are inherited from the upper client if present unless overridden.\n    clientConfig: {},\n  }),\n});\n```\n\n## `fromTemporaryCredentials()`\n\n- Uses `@aws-sdk/client-sts`\n- Available in browsers & native apps\n\nThe function `fromTemporaryCredentials` returns `AwsCredentialIdentityProvider` that retrieves temporary\ncredentials from [STS AssumeRole API][assumerole_api].\n\n```javascript\nimport { fromTemporaryCredentials } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  region,\n  credentials: fromTemporaryCredentials({\n    // Optional. The master credentials used to get and refresh temporary credentials from AWS STS.\n    // If skipped, it uses the default credential resolved by internal STS client.\n    masterCredentials: fromTemporaryCredentials({\n      params: { RoleArn: \"arn:aws:iam::1234567890:role/RoleA\" },\n    }),\n    // Required. Options passed to STS AssumeRole operation.\n    params: {\n      // Required. ARN of role to assume.\n      RoleArn: \"arn:aws:iam::1234567890:role/RoleB\",\n      // Optional. An identifier for the assumed role session. If skipped, it generates a random\n      // session name with prefix of 'aws-sdk-js-'.\n      RoleSessionName: \"aws-sdk-js-123\",\n      // Optional. The duration, in seconds, of the role session.\n      DurationSeconds: 3600,\n      // ... For more options see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html\n    },\n    // Optional. A function that returns a promise fulfilled with an MFA token code for the provided\n    // MFA Serial code. Required if `params` has `SerialNumber` config.\n    mfaCodeProvider: async (mfaSerial) => {\n      return \"token\";\n    },\n    // Optional overrides. This is passed to an inner STS client instantiated to\n    // resolve the credentials. Region and profile\n    // are inherited from the upper client if present unless overridden.\n    clientConfig: {},\n  }),\n});\n```\n\n## `fromWebToken()`\n\n- Uses `@aws-sdk/client-sts`\n- Available in browsers & native apps\n\nThe function `fromWebToken` returns an `AwsCredentialIdentityProvider` that gets credentials calling\n[STS AssumeRoleWithWebIdentity API][assumerolewithwebidentity_api]\n\n```javascript\nimport { fromWebToken } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  region,\n  credentials: fromWebToken({\n    // Required. ARN of the role that the caller is assuming.\n    roleArn: \"arn:aws:iam::1234567890:role/RoleA\",\n    // Required. The OAuth 2.0 access token or OpenID Connect ID token that is\n    // provided by the identity provider.\n    webIdentityToken: await openIdProvider(),\n    // Optional. A function that assumes a role with web identity and returns\n    // a promise fulfilled with credentials for the assumed role.\n    roleAssumerWithWebIdentity,\n    // Optional. An identifier for the assumed role session.\n    roleSessionName: \"session_123\",\n    // Optional. The fully qualified host component of the domain name of the\n    // identity provider.\n    providerId: \"graph.facebook.com\",\n    // Optional. ARNs of the IAM managed policies that you want to use as\n    // managed session.\n    policyArns: [{ arn: \"arn:aws:iam::1234567890:policy/SomePolicy\" }],\n    // Optional. An IAM policy in JSON format that you want to use as an\n    // inline session policy.\n    policy: \"JSON_STRING\",\n    // Optional. The duration, in seconds, of the role session. Default 3600.\n    durationSeconds: 7200,\n    // Optional overrides. This is passed to an inner STS client\n    // instantiated to resolve the credentials. Region and profile\n    // are inherited from the upper client if present unless overridden.\n    clientConfig: {},\n  }),\n});\n```\n\n### Examples\n\nYou can directly configure individual identity providers to access AWS resources using web identity\nfederation. AWS currently supports authenticating users using web identity federation through\nseveral identity providers:\n\n- [Login with Amazon](https://login.amazon.com/)\n\n- [Facebook Login](https://developers.facebook.com/docs/facebook-login/web/)\n\n- [Google Sign-in](https://developers.google.com/identity/)\n\nYou must first register your application with the providers that your application supports. Next,\ncreate an IAM role and set up permissions for it. The IAM role you create is then used to grant the\npermissions you configured for it through the respective identity provider. For example, you can set\nup a role that allows users who logged in through Facebook to have read access to a specific Amazon\nS3 bucket you control.\n\nAfter you have both an IAM role with configured privileges and an application registered with your\nchosen identity providers, you can set up the SDK to get credentials for the IAM role using helper\ncode, as follows:\n\nThe value in the ProviderId parameter depends on the specified identity provider. The value in the\nWebIdentityToken parameter is the access token retrieved from a successful login with the identity\nprovider. For more information on how to configure and retrieve access tokens for each identity\nprovider, see the documentation for the identity provider.\n\n## `fromContainerMetadata()` and `fromInstanceMetadata()`\n\n- Not available in browsers & native apps\n\n`fromContainerMetadata` and `fromInstanceMetadata` will create `AwsCredentialIdentityProvider` functions that\nread from the ECS container metadata service and the EC2 instance metadata service, respectively.\n\n```javascript\nimport { fromInstanceMetadata } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  credentials: fromInstanceMetadata({\n    // Optional. The connection timeout (in milliseconds) to apply to any remote requests.\n    // If not specified, a default value of `1000` (one second) is used.\n    timeout: 1000,\n    // Optional. The maximum number of times any HTTP connections should be retried. If not\n    // specified, a default value of `0` will be used.\n    maxRetries: 0,\n  }),\n});\n```\n\n```javascript\nimport { fromContainerMetadata } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  credentials: fromContainerMetadata({\n    // Optional. The connection timeout (in milliseconds) to apply to any remote requests.\n    // If not specified, a default value of `1000` (one second) is used.\n    timeout: 1000,\n    // Optional. The maximum number of times any HTTP connections should be retried. If not\n    // specified, a default value of `0` will be used.\n    maxRetries: 0,\n  }),\n});\n```\n\nAn `AwsCredentialIdentityProvider` function created with `fromContainerMetadata` will return a promise that will\nresolve with credentials for the IAM role associated with containers in an Amazon ECS task. Please\nsee [IAM Roles for Tasks][iam_roles_for_tasks] for more information on using IAM roles with Amazon\nECS.\n\nAn `AwsCredentialIdentityProvider` function created with `fromInstanceMetadata` will return a promise that will\nresolve with credentials for the IAM role associated with an EC2 instance.\nPlease see [IAM Roles for Amazon EC2][iam_roles_for_ec2] for more information on using IAM roles\nwith Amazon EC2. Both IMDSv1 (a request/response method) and IMDSv2 (a session-oriented method) are\nsupported.\n\nPlease see [Configure the instance metadata service][config_instance_metadata] for more information.\n\n## `fromHttp()`\n\n- Available in browsers & native apps, without the EC2 and Container metadata components.\n\nThis creates a provider function that makes a `GET` request to\nany provided HTTPS URL. A limited set of HTTP destinations are also accepted.\n\nThis is a general form of the `fromContainerMetadata` function.\n\nThe server is expected to respond with the following format in JSON:\n\n```ts\ntype HttpProviderResponse = {\n  AccessKeyId: string;\n  SecretAccessKey: string;\n  Token: string;\n  AccountId?: string;\n  Expiration: string; // rfc3339\n};\n```\n\nThe acceptable non-HTTPS destinations are described in the validation error if encountered:\n\n```\nURL not accepted. It must either be HTTPS or match one of the following:\n  - loopback CIDR 127.0.0.0/8 or [::1/128]\n  - ECS container host 169.254.170.2\n  - EKS container host 169.254.170.23 or [fd00:ec2::23]\n```\n\nNode.js:\n\n```js\nimport { fromHttp } from \"@aws-sdk/credential-providers\";\n\nconst client = new FooClient({\n  credentials: fromHttp({\n    /**\n     * If this value is provided, it will be used as-is.\n     */\n    awsContainerCredentialsFullUri: \"...\",\n    /**\n     * If this value is provided instead of the full URI, it\n     * will be appended to the default link local host of 169.254.170.2.\n     */\n    awsContainerCredentialsRelativeUri: \"...\",\n\n    /**\n     * Will be read on each credentials request to\n     * add an Authorization request header value.\n     */\n    awsContainerAuthorizationTokenFile: \"...\",\n\n    /**\n     * An alternative to awsContainerAuthorizationTokenFile,\n     * this is the token value itself.\n     */\n    awsContainerAuthorizationToken: \"...\",\n  }),\n});\n```\n\nIf not provided in the JavaScript code, the following process envrionment variables will\nbe read:\n\n```\nAWS_CONTAINER_CREDENTIALS_RELATIVE_URI\nAWS_CONTAINER_CREDENTIALS_FULL_URI\nAWS_CONTAINER_AUTHORIZATION_TOKEN_FILE\nAWS_CONTAINER_AUTHORIZATION_TOKEN\n```\n\nBrowsers:\n\n```js\nimport { fromHttp } from \"@aws-sdk/credential-providers\";\n\nconst client = new FooClient({\n  credentials: fromHttp({\n    /**\n     * BROWSER ONLY.\n     *\n     * In browsers, a relative URI is not allowed, and a full URI must be provided.\n     * HTTPS is required.\n     *\n     * This value is required for the browser environment.\n     */\n    credentialsFullUri: \"...\",\n\n    /**\n     * BROWSER ONLY.\n     *\n     * Providing this value will set an \"Authorization\" request\n     * header value on the GET request.\n     */\n    authorizationToken: \"...\",\n  }),\n});\n```\n\n## `fromIni()`\n\n- May use `@aws-sdk/client-sso` or `@aws-sdk/client-sts` depending\n  on how the file is configured.\n- Not available in browsers & native apps.\n\n`fromIni` creates an `AwsCredentialIdentityProvider` function that reads from a shared credentials file at\n`~/.aws/credentials` and a shared configuration file at `~/.aws/config`. Both files are expected to\nbe INI formatted with section names corresponding to profiles. Sections in the credentials file are\ntreated as profile names, whereas profile sections in the config file must have the format of\n`[profile profile-name]`, except for the default profile. Please see the\n[sample files](#sample-files) below for examples of well-formed configuration and credentials files.\n\nProfiles that appear in both files will not be merged, and the version that appears in the\ncredentials file will be given precedence over the profile found in the config file.\n\n```javascript\nimport { fromIni } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  // As of v3.714.0, an easy way to select a profile is to set it on the client.\n  // This will read both client configuration and credentials instructions\n  // from that profile. The order of priority is:\n  // 1. this field (only applies to this client).\n  // 2. AWS_PROFILE environment variable (affects all clients).\n  // 3. the default profile.\n  profile: \"my-profile\",\n\n  // Please note that the data client's region\n  // will not be used by STS requests originating from the `fromIni`\n  // provider if the profile(s) used have their own configured regions.\n  // If the profile(s) have no regions set, then the data client's\n  // region will be the fallback for the inner STS client.\n  // For SSO via `fromIni`, the `sso_region` value will be used, since it is required.\n  region: \"us-west-2\",\n\n  credentials: fromIni({\n    // Optional. Defaults to the client's profile if that is set.\n    // You can specify a profile here as well, but this applies\n    // only to the credential resolution and not to the upper client.\n    // Use this instead of the client profile if you need a separate profile\n    // for credentials.\n    profile: \"my-profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n    // Optional. A function that returns a a promise fulfilled with an MFA token code for the\n    // provided MFA Serial code. If a profile requires an MFA code and `mfaCodeProvider` is not a\n    // valid function, the credential provider promise will be rejected.\n    mfaCodeProvider: async (mfaSerial) => {\n      return \"token\";\n    },\n    // Optional overrides. This is passed to an inner STS or SSO client\n    // instantiated to resolve the credentials. Region and profile\n    // are inherited from the upper client if present unless overridden, so\n    // it should not be necessary to set those.\n    //\n    // Warning: setting a region here overrides the region set in the config file\n    // for the selected profile.\n    clientConfig: {},\n  }),\n});\n```\n\n### Sample files\n\n#### `~/.aws/credentials`\n\n```ini\n[default]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[dev]\naws_access_key_id=foo2\naws_secret_access_key=bar2\n```\n\n#### `~/.aws/config`\n\n```ini\n[default]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[profile dev]\naws_access_key_id=foo2\naws_secret_access_key=bar2\n```\n\n#### profile with source profile\n\n```ini\n[second]\naws_access_key_id=foo\naws_secret_access_key=bar\n\n[first]\nsource_profile=second\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\n```\n\n#### profile with source provider\n\nYou can supply `credential_source` options to tell the SDK where to source credentials for the call\nto `AssumeRole`. The supported credential providers are listed below:\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = Ec2InstanceMetadata\n```\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = Environment\n```\n\n```ini\n[default]\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\ncredential_source = EcsContainer\n```\n\n#### profile with web_identity_token_file\n\n```ini\n[default]\nweb_identity_token_file=/temp/token\nrole_arn=arn:aws:iam::123456789012:role/example-role-arn\n```\n\nYou can specify another profile(`second`) whose credentials are used to assume the role by the\n`role_arn` setting in this profile(`first`).\n\n```ini\n[second]\nweb_identity_token_file=/temp/token\nrole_arn=arn:aws:iam::123456789012:role/example-role-2\n\n[first]\nsource_profile=second\nrole_arn=arn:aws:iam::123456789012:role/example-role\n```\n\n#### profile with sso credentials\n\nSee [`fromSSO()`](#fromsso) for more information\n\n## `fromEnv()`\n\n- Not available in browser & native apps\n\n```javascript\nimport { fromEnv } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  credentials: fromEnv(),\n});\n```\n\n`fromEnv` returns an `AwsCredentialIdentityProvider` function, that reads credentials from the following\nenvironment variables:\n\n- `AWS_ACCESS_KEY_ID` - The access key for your AWS account.\n- `AWS_SECRET_ACCESS_KEY` - The secret key for your AWS account.\n- `AWS_SESSION_TOKEN` - The session key for your AWS account. This is only needed when you are using\n  temporary credentials.\n- `AWS_CREDENTIAL_EXPIRATION` - The expiration time of the credentials contained in the environment\n  variables described above. This value must be in a format compatible with the\n  [ISO-8601 standard][iso8601_standard] and is only needed when you are using temporary credentials.\n\nIf either the `AWS_ACCESS_KEY_ID` or `AWS_SECRET_ACCESS_KEY` environment variable is not set or\ncontains a falsy value, the promise returned by the `fromEnv` function will be rejected.\n\n## `fromProcess()`\n\n- Not available in browsers & native apps\n\n```javascript\nimport { fromProcess } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  // Optional, available on clients as of v3.714.0.\n  profile: \"my-profile\",\n  credentials: fromProcess({\n    // Optional. Defaults to the client's profile if that is set.\n    // You can specify a profile here as well, but this applies\n    // only to the credential resolution and not to the upper client.\n    // Use this instead of the client profile if you need a separate profile\n    // for credentials.\n    profile: \"my-profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n  }),\n});\n```\n\n`fromProcess` creates an `AwsCredentialIdentityProvider` functions that executes a given process and\nattempt to read its standard output to receive a JSON payload containing the credentials. The\nprocess command is read from a shared credentials file at `~/.aws/credentials` and a shared\nconfiguration file at `~/.aws/config`. Both files are expected to be INI formatted with section\nnames corresponding to profiles. Sections in the credentials file are treated as profile names,\nwhereas profile sections in the config file must have the format of`[profile profile-name]`, except\nfor the default profile. Please see the [sample files](#sample-files-1) below for examples of\nwell-formed configuration and credentials files.\n\nProfiles that appear in both files will not be merged, and the version that appears in the\ncredentials file will be given precedence over the profile found in the config file.\n\n### Sample files\n\n#### `~/.aws/credentials`\n\n```ini\n[default]\ncredential_process = /usr/local/bin/awscreds\n\n[dev]\ncredential_process = /usr/local/bin/awscreds dev\n```\n\n#### `~/.aws/config`\n\n```ini\n[default]\ncredential_process = /usr/local/bin/awscreds\n\n[profile dev]\ncredential_process = /usr/local/bin/awscreds dev\n```\n\n## `fromTokenFile()`\n\n- Uses `@aws-sdk/client-sts`\n- Not available in browsers & native apps\n\nThe function `fromTokenFile` returns `AwsCredentialIdentityProvider` that reads credentials as follows:\n\n- Reads file location of where the OIDC token is stored from either provided option\n  `webIdentityTokenFile` or environment variable `AWS_WEB_IDENTITY_TOKEN_FILE`.\n- Reads IAM role wanting to be assumed from either provided option `roleArn` or environment\n  variable `AWS_ROLE_ARN`.\n- Reads optional role session name to be used to distinguish sessions from provided option\n  `roleSessionName` or environment variable `AWS_ROLE_SESSION_NAME`. If session name is not defined,\n  it comes up with a role session name.\n- Reads OIDC token from file on disk.\n- Calls sts:AssumeRoleWithWebIdentity via `roleAssumerWithWebIdentity` option to get credentials.\n\n| **Configuration Key** | **Environment Variable**    | **Required** | **Description**                                   |\n| --------------------- | --------------------------- | ------------ | ------------------------------------------------- |\n| webIdentityTokenFile  | AWS_WEB_IDENTITY_TOKEN_FILE | true         | File location of where the `OIDC` token is stored |\n| roleArn               | AWS_ROLE_ARN                | true         | The IAM role wanting to be assumed                |\n| roleSessionName       | AWS_ROLE_SESSION_NAME       | false        | The IAM session name used to distinguish sessions |\n\n```javascript\nimport { fromTokenFile } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  region: \"us-west-2\",\n  credentials: fromTokenFile({\n    // Optional overrides. This is passed to an inner STS client\n    // instantiated to resolve the credentials. Region is inherited\n    // from the upper client if present unless overridden.\n    clientConfig: {},\n  }),\n});\n```\n\n## `fromSSO()`\n\n- Uses `@aws-sdk/client-sso` & `@aws-sdk/client-sso-oidc`\n- Not available in browsers & native apps\n\n> This credential provider **ONLY** supports profiles using the SSO credential. If you have a\n> profile that assumes a role which derived from the SSO credential, you should use the\n> [`fromIni()`](#fromini), or `@aws-sdk/credential-provider-node` package.\n\n`fromSSO`, that creates `AwsCredentialIdentityProvider` functions that read from the _resolved_ access token\nfrom local disk then requests temporary AWS credentials. For guidance on the AWS Single Sign-On\nservice, please refer to [AWS's Single Sign-On documentation][sso_api].\n\nYou can create the `AwsCredentialIdentityProvider` functions using the inline SSO parameters(`ssoStartUrl`,\n`ssoAccountId`, `ssoRegion`, `ssoRoleName`) or load them from\n[AWS SDKs and Tools shared configuration and credentials files][shared_config_files].\nProfiles in the `credentials` file are given precedence over profiles in the `config` file.\n\nThis credential provider is intended for use with the AWS SDK for Node.js.\n\n### Supported configuration\n\nYou may customize how credentials are resolved by providing an options hash to the `fromSSO` factory\nfunction. You can either load the SSO config from shared INI credential files, or specify the\n`ssoStartUrl`, `ssoAccountId`, `ssoRegion`, and `ssoRoleName` directly from the code.\n\n```javascript\nimport { fromSSO } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  // Optional, available on clients as of v3.714.0.\n  profile: \"my-sso-profile\",\n  credentials: fromSSO({\n    // Optional. Defaults to the client's profile if that is set.\n    // You can specify a profile here as well, but this applies\n    // only to the credential resolution and not to the upper client.\n    // Use this instead of the client profile if you need a separate profile\n    // for credentials.\n    profile: \"my-sso-profile\",\n    // Optional. The path to the shared credentials file. If not specified, the provider will use\n    // the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of\n    // `~/.aws/credentials`.\n    filepath: \"~/.aws/credentials\",\n    // Optional. The path to the shared config file. If not specified, the provider will use the\n    // value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.\n    configFilepath: \"~/.aws/config\",\n    // Optional. The URL to the AWS SSO service. Required if any of the `sso*` options(except for\n    // `ssoClient`) is provided.\n    ssoStartUrl: \"https://d-abc123.awsapps.com/start\",\n    // Optional. The ID of the AWS account to use for temporary credentials. Required if any of the\n    // `sso*` options(except for `ssoClient`) is provided.\n    ssoAccountId: \"1234567890\",\n    // Optional. The AWS region to use for temporary credentials. Required if any of the `sso*`\n    // options(except for `ssoClient`) is provided.\n    ssoRegion: \"us-east-1\",\n    // Optional. The name of the AWS role to assume. Required if any of the `sso*` options(except\n    // for `ssoClient`) is provided.\n    ssoRoleName: \"SampleRole\",\n    // Optional. Overwrite the configuration used construct the SSO service client. If not\n    // specified, a default SSO client will be created with the region specified in the profile\n    // `sso_region` entry.\n    clientConfig: { region },\n  }),\n});\n```\n\n### SSO Login with the AWS CLI\n\nThis credential provider relies on the [AWS CLI][cli_sso] to log into an AWS SSO session. Here's a\nbrief walk-through:\n\n1. Create a new AWS SSO enabled profile using the AWS CLI. It will ask you to login to your AWS SSO\n   account and prompt for the name of the profile:\n\n```console\n$ aws configure sso\n...\n...\nCLI profile name [123456789011_ReadOnly]: my-sso-profile<ENTER>\n```\n\n2. Configure your SDK client with the SSO credential provider:\n\n```javascript\n//...\nconst client = new FooClient({ credentials: fromSSO({ profile: \"my-sso-profile\" }) });\n```\n\nAlternatively, the SSO credential provider is supported in shared INI credentials provider\n\n```javascript\n//...\nconst client = new FooClient({ credentials: fromIni({ profile: \"my-sso-profile\" }) });\n```\n\n3. To log out from the current SSO session, use the AWS CLI:\n\n```console\n$ aws sso logout\nSuccessfully signed out of all SSO profiles.\n```\n\n### Sample files\n\nThis credential provider is only applicable if the profile specified in shared configuration and\ncredentials files contain ALL of the following entries.\n\n#### `~/.aws/credentials`\n\n```ini\n[sample-profile]\nsso_account_id = 012345678901\nsso_region = us-east-1\nsso_role_name = SampleRole\nsso_start_url = https://d-abc123.awsapps.com/start\n```\n\n#### `~/.aws/config`\n\n```ini\n[profile sample-profile]\nsso_account_id = 012345678901\nsso_region = us-east-1\nsso_role_name = SampleRole\nsso_start_url = https://d-abc123.awsapps.com/start\n```\n\n## `fromLoginCredentials()`\n\n- Uses `@aws-sdk/client-signin`\n- Not available in browsers & native apps\n\n`fromLoginCredentials` creates an `AwsCredentialIdentityProvider` function that reads from cached login credentials stored on disk after authenticating with the AWS CLI using the `aws login` command. The provider automatically refreshes when the credentials are about to expire.\n\nThis provider is not typically used in an explicit fashion and is designed to simplify credential usage by allowing SDK clients to work seamlessly after running `aws login` with AWS CLI, without requiring any additional configuration.\n\n```javascript\nimport { fromLoginCredentials } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst client = new FooClient({\n  // Optional, available on clients as of v3.714.0.\n  profile: \"my-profile\",\n  credentials: fromLoginCredentials({\n    // Optional. Defaults to the client's profile if that is set.\n    // Should match the profile name used with 'aws login --profile <name>'\n    // to ensure credentials are found in the cache. Uses 'default' if no\n    // --profile was specified during aws login or if this option is omitted.\n    profile: \"my-profile\",\n    // Optional. Overwrite the configuration used to construct the signin service client.\n    // If not specified, a default signin client will be created with the region specified in the profile.\n    // Warning: setting a region here overrides the region set in the config file\n    // for the selected profile.\n    clientConfig: { region },\n  }),\n});\n```\n\n### Login with AWS CLI\n\nThis credential provider relies on the AWS CLI to authenticate and cache login credentials. Here's how to set it up:\n\n1. **Initial Login**: Run the `aws login` command to authenticate using your existing AWS Management Console credentials:\n\n```console\n$ aws login\n```\n\n2. **Named Profile**: To sign in to a named profile or create a new one, use the `--profile` option:\n\n```console\n$ aws login --profile my-dev-profile\n```\n\n3. **Region Configuration**: If this is a new profile or no AWS Region has been specified, the AWS CLI prompts you to provide a region:\n\n```console\nNo AWS region has been configured. The AWS region is the geographic location of\nyour AWS resources.\n\nIf you've used AWS before and already have resources in your account, tell us\nwhich region they were created in. If you haven't created resources in your account\nbefore, you can pick the region closest to you:\nhttps://docs.aws.amazon.com/global-infrastructure/latest/regions/aws-regions.html.\nYou are able to change the region in the CLI at any time with the command\n`aws configure set region NEW_REGION`.\n\nAWS Region [us-east-1]:\n```\n\n4. **Browser Authentication**: The AWS CLI attempts to open your default browser for the sign in process:\n\n```console\nAttempting to open the login page for `us-east-1` in your default browser.\nIf the browser does not open, use the following URL to complete your login:\nhttps://signin.us-east-1.amazonaws.com/authorize?<abbreviated>\n```\n\n5. **No Browser Option**: If the device using the AWS CLI does not have a browser, you can use the `--no-browser` option:\n\n```console\n$ aws login --no-browser\n```\n\nThis will provide a URL for you to open on a browser-enabled device and prompt for an authorization code.\n\n6. **Logout**: When you are done using your session, you can let your credentials expire, or run the `aws logout` command:\n\n```console\n$ aws logout\n$ aws logout --profile my-dev-profile\n```\n\n### Cached Credentials\n\nThe temporary cached credentials, as well as the metadata required to refresh them are stored by default in `~/.aws/login/cache` on Linux and macOS, or `%USERPROFILE%\\.aws\\login\\cache` on Windows.\n\nYou can override this location by setting the `AWS_LOGIN_CACHE_DIRECTORY` environment variable.\n\n### Sample Files\n\nAfter running `aws login`, the configuration file will contain a `login_session` entry:\n\n#### `~/.aws/config`\n\n```ini\n[default]\nlogin_session = arn:aws:iam::0123456789012:user/username\nregion = us-east-1\n```\n\n## `fromNodeProviderChain()`\n\n- May use `@aws-sdk/client-sts`, `@aws-sdk/client-sso`, etc. depending on\n  which link in the chain finally resolves credentials.\n- Not available in browsers & native apps\n\nThe credential provider used as default in the Node.js clients, but with default role assumers so\nyou don't need to import them from STS client and supply them manually. You normally don't need\nto use this explicitly in the client constructor. It is useful for utility functions requiring\ncredentials like S3 presigner, or RDS signer.\n\nThis credential provider will attempt to find credentials from the following sources (listed in\norder of precedence):\n\n- [Environment variables exposed via `process.env`](#fromenv)\n- [SSO credentials from token cache](#fromsso)\n- [Web identity token credentials](#fromtokenfile)\n- [Shared credentials and config ini files](#fromini)\n- [The EC2/ECS Instance Metadata Service](#fromcontainermetadata-and-frominstancemetadata)\n\nThis credential provider will invoke one provider at a time and only\ncontinue to the next if no credentials have been located. For example, if\nthe process finds values defined via the `AWS_ACCESS_KEY_ID` and\n`AWS_SECRET_ACCESS_KEY` environment variables, the files at\n`~/.aws/credentials` and `~/.aws/config` will not be read, nor will any\nmessages be sent to the Instance Metadata Service\n\n```js\nimport { fromNodeProviderChain } from \"@aws-sdk/credential-providers\"; // ES6 import\n\nconst credentialProvider = fromNodeProviderChain({\n  // This provider accepts any input of fromEnv(), fromSSO(), fromTokenFile(),\n  // fromIni(), fromProcess(), fromInstanceMetadata(), fromContainerMetadata()\n  // that exist in the default credential chain.\n\n  // Optional client overrides. This is passed to an inner credentials client\n  // that may be STS, SSO, or other instantiated to resolve the credentials.\n  // Region and profile are inherited from the upper client if present\n  // unless overridden, so it should not be necessary to set those.\n  //\n  // Warning: setting a region here may override the region set in\n  // the config file for the selected profile if profile-based\n  // credentials are used.\n  clientConfig: {},\n});\n```\n\n## `createCredentialChain()`\n\nYou can use this helper to create a credential chain of your own.\n\nA credential chain is created from a list of functions of the signature () =>\nPromise<[AwsCredentialIdentity](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-types/Interface/AwsCredentialIdentity/)>,\ncomposed together such that the overall chain has the **same** signature.\n\nThat is why you can provide the chained credential provider to the same field (`credentials`) as any single provider\nfunction.\n\nAll the providers from this package are compatible, and can be used to create such a chain.\n\nAs with _any_ function provided to the `credentials` SDK client constructor configuration field, if the credential\nobject returned does not contain\nan `expiration` (type `Date`), the client will only ever call the provider function once. You do not need to memoize\nthis function.\n\nTo enable automatic refresh, the credential provider function should set an `expiration` (`Date`) field. When this\nexpiration approaches within 5 minutes, the\nprovider function will be called again by the client in the course of making SDK requests.\n\nTo assist with this, the `createCredentialChain` has a chainable helper `.expireAfter(milliseconds: number)`. An example\nis included below.\n\n```ts\nimport { fromEnv, fromIni, createCredentialChain } from \"@aws-sdk/credential-providers\";\nimport { S3 } from \"@aws-sdk/client-s3\";\n\n// You can mix existing AWS SDK credential providers\n// and custom async functions returning credential objects.\nnew S3({\n  credentials: createCredentialChain(\n    fromEnv(),\n    async () => {\n      // credentials customized by your code...\n      return credentials;\n    },\n    fromIni()\n  ),\n});\n\n// Set a max duration on the credentials (client side only).\n// A set expiration will cause the credentials function to be called again\n// when the time left is less than 5 minutes.\nnew S3({\n  // This setting indicates expiry after 15 minutes (in milliseconds) with `15 * 60_000`.\n  // Due to the 5 minute expiry window, the function will be called approximately every\n  // 10 minutes under continuous usage of this client.\n  credentials: createCredentialChain(fromEnv(), fromIni()).expireAfter(15 * 60_000),\n});\n\n// Apply shared init properties.\nconst init = { logger: console };\n\nnew S3({\n  credentials: createCredentialChain(fromEnv(init), fromIni(init)),\n});\n```\n\n[getcredentialsforidentity_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetCredentialsForIdentity.html\n[getid_api]: https://docs.aws.amazon.com/cognitoidentity/latest/APIReference/API_GetId.html\n[assumerole_api]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html\n[assumerolewithwebidentity_api]: https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html\n[iam_roles_for_tasks]: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html\n[iam_roles_for_ec2]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html\n[config_instance_metadata]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html\n[iso8601_standard]: https://en.wikipedia.org/wiki/ISO_8601\n[sso_api]: https://aws.amazon.com/single-sign-on/\n[shared_config_files]: https://docs.aws.amazon.com/credref/latest/refdocs/creds-config-files.html\n[cli_sso]: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html#sso-configure-profile\n","publish_time":1781808484560,"_cnpm_publish_time":1781808484560,"dist-tags":{"latest":"3.1163.0"}}