@@ -72,7 +72,7 @@ export class SDK {
72
72
} ) ;
73
73
}
74
74
75
- this . defaultAwsAccount = new DefaultAWSAccount ( defaultCredentialProvider ) ;
75
+ this . defaultAwsAccount = new DefaultAWSAccount ( defaultCredentialProvider , getCLICompatibleDefaultRegion ( this . profile ) ) ;
76
76
this . credentialsCache = new CredentialsCache ( this . defaultAwsAccount , defaultCredentialProvider ) ;
77
77
}
78
78
@@ -206,7 +206,9 @@ class DefaultAWSAccount {
206
206
private defaultAccountId ?: string = undefined ;
207
207
private readonly accountCache = new AccountAccessKeyCache ( ) ;
208
208
209
- constructor ( private readonly defaultCredentialsProvider : Promise < AWS . CredentialProviderChain > ) {
209
+ constructor (
210
+ private readonly defaultCredentialsProvider : Promise < AWS . CredentialProviderChain > ,
211
+ private readonly region : Promise < string | undefined > ) {
210
212
}
211
213
212
214
/**
@@ -222,6 +224,10 @@ class DefaultAWSAccount {
222
224
223
225
private async lookupDefaultAccount ( ) : Promise < string | undefined > {
224
226
try {
227
+ // There just is *NO* way to do AssumeRole credentials as long as AWS_SDK_LOAD_CONFIG is not set. The SDK
228
+ // crash if the file does not exist though. So set the environment variable if we can find that file.
229
+ await setConfigVariable ( ) ;
230
+
225
231
debug ( 'Resolving default credentials' ) ;
226
232
const credentialProvider = await this . defaultCredentialsProvider ;
227
233
const creds = await credentialProvider . resolvePromise ( ) ;
@@ -234,7 +240,7 @@ class DefaultAWSAccount {
234
240
const accountId = await this . accountCache . fetch ( creds . accessKeyId , async ( ) => {
235
241
// if we don't have one, resolve from STS and store in cache.
236
242
debug ( 'Looking up default account ID from STS' ) ;
237
- const result = await new AWS . STS ( { credentials : creds } ) . getCallerIdentity ( ) . promise ( ) ;
243
+ const result = await new AWS . STS ( { credentials : creds , region : await this . region } ) . getCallerIdentity ( ) . promise ( ) ;
238
244
const aid = result . Account ;
239
245
if ( ! aid ) {
240
246
debug ( 'STS didn\'t return an account ID' ) ;
@@ -389,6 +395,15 @@ async function hasEc2Credentials() {
389
395
return instance ;
390
396
}
391
397
398
+ async function setConfigVariable ( ) {
399
+ const homeDir = process . env . HOME || process . env . USERPROFILE
400
+ || ( process . env . HOMEPATH ? ( ( process . env . HOMEDRIVE || 'C:/' ) + process . env . HOMEPATH ) : null ) || os . homedir ( ) ;
401
+
402
+ if ( await fs . pathExists ( path . resolve ( homeDir , '.aws' , 'config' ) ) ) {
403
+ process . env . AWS_SDK_LOAD_CONFIG = '1' ;
404
+ }
405
+ }
406
+
392
407
async function readIfPossible ( filename : string ) : Promise < string | undefined > {
393
408
try {
394
409
if ( ! await fs . pathExists ( filename ) ) { return undefined ; }
0 commit comments