@@ -27,6 +27,8 @@ A collection of all credential providers.
2727 1 . [ Sample Files] ( #sample-files-2 )
28281 . [ From Node.js default credentials provider chain] ( #fromnodeproviderchain )
29291 . [ Creating a custom credentials chain] ( #createcredentialchain )
30+ 1 . [ Aws CliV2 Region resolution order] ( #resolveAwsCliV2Region )
31+ 1 . [ From AwsCliV2 compatible provider chain] ( #fromAwsCliV2CompatibleProviderChain )
3032
3133## Terminology
3234
@@ -948,6 +950,77 @@ new S3({
948950});
949951```
950952
953+ ## ` resolveAwsCliV2Region() `
954+
955+ The region is resolved using the following order of precedence (highest to lowest) in the cli v2.
956+
957+ 1 . Environment Variables
958+ - AWS_REGION
959+ - AWS_DEFAULT_REGION
960+ 2 . AWS Configuration Files
961+ - Profile specific region from ~ /.aws/config or ~ /.aws/credentials
962+ - Profile selection order:
963+ 1 . Explicitly provided profile
964+ 2 . AWS_PROFILE environment variable
965+ 3 . AWS_DEFAULT_PROFILE environment variable
966+ 4 . "default" profile
967+ 3 . EC2/ECS Instance Metadata Service
968+ - Region from instance identity document
969+ - Automatically falls back if metadata service is unavailable
970+ 4 . Default Region
971+ - Uses provided default region if specified
972+ - Returns undefined if no region can be determined
973+
974+ Basic Usage
975+
976+ ```
977+ import { resolveAwsCliV2Region } from "@aws-sdk/credential-providers";
978+ import { S3Client } from "@aws-sdk/client-s3";
979+
980+ const client = new S3Client({
981+ region: await resolveAwsCliV2Region({})
982+ });
983+
984+ ```
985+
986+ ## ` fromAwsCliV2CompatibleProviderChain() `
987+
988+ A credential provider that follows the same priority chain as AWS CLI v2 for credential resolution.
989+ This credential provider will attempt to find credentials from the following sources (listed in
990+ order of precedence):
991+
992+ - Static credentials
993+ - [ Shared credentials and config ini files] ( #fromini ) when a profile is specified
994+ - [ Environment variables exposed via ` process.env ` ] ( #fromenv )
995+ - [ Web identity token credentials] ( #fromtokenfile )
996+ - [ SSO credentials from token cache] ( #fromsso )
997+ - [ From Credential Process] ( #fromprocess )
998+ - [ From Instance and Container Metadata Service] ( #fromcontainermetadata-and-frominstancemetadata )
999+
1000+ Example:
1001+
1002+ ```
1003+ Import {
1004+ fromAwsCliV2CompatibleProviderChain,
1005+ resolveAwsCliV2Region
1006+ } from "@aws-sdk/credential-providers";
1007+ import { S3Client } from "@aws-sdk/client-s3";
1008+
1009+ const s3Client = new S3Client({
1010+ profile: 'application-profile',
1011+
1012+ // Implements AWS CLI-compatible credential resolution and proxy settings.
1013+ credentials: fromAwsCliV2CompatibleProviderChain({
1014+ proxyUrl: "http://localhost:8080", // Optional: Uses proxy settings.
1015+ certificateBundle: "/home/user/certificate.pem", // Optional: Custom CA bundle.
1016+ }),
1017+
1018+ // Implements AWS CLI region resolution logic.
1019+ region: resolveAwsCliV2Region(),
1020+ // Other configurations like retry strategy, logging, etc.
1021+ });
1022+ ```
1023+
9511024## Add Custom Headers to STS assume-role calls
9521025
9531026You can specify the plugins--groups of middleware, to inject to the STS client.
0 commit comments