@@ -48,7 +48,6 @@ export interface SDKOptions {
48
48
export class SDK {
49
49
private readonly defaultAwsAccount : DefaultAWSAccount ;
50
50
private readonly credentialsCache : CredentialsCache ;
51
- private readonly defaultClientArgs : any = { } ;
52
51
private readonly profile ?: string ;
53
52
54
53
constructor ( options : SDKOptions ) {
@@ -58,52 +57,50 @@ export class SDK {
58
57
59
58
// Find the package.json from the main toolkit
60
59
const pkg = ( require . main as any ) . require ( '../package.json' ) ;
61
- this . defaultClientArgs . userAgent = `${ pkg . name } /${ pkg . version } ` ;
60
+ AWS . config . update ( {
61
+ customUserAgent : `${ pkg . name } /${ pkg . version } `
62
+ } ) ;
62
63
63
64
// https://aws.amazon.com/blogs/developer/using-the-aws-sdk-for-javascript-from-behind-a-proxy/
64
65
if ( options . proxyAddress === undefined ) {
65
66
options . proxyAddress = httpsProxyFromEnvironment ( ) ;
66
67
}
67
68
if ( options . proxyAddress ) { // Ignore empty string on purpose
68
69
debug ( 'Using proxy server: %s' , options . proxyAddress ) ;
69
- this . defaultClientArgs . httpOptions = {
70
- agent : require ( 'proxy-agent' ) ( options . proxyAddress )
71
- } ;
70
+ AWS . config . update ( {
71
+ httpOptions : { agent : require ( 'proxy-agent' ) ( options . proxyAddress ) }
72
+ } ) ;
72
73
}
73
74
74
- this . defaultAwsAccount = new DefaultAWSAccount ( defaultCredentialProvider , this . defaultClientArgs ) ;
75
+ this . defaultAwsAccount = new DefaultAWSAccount ( defaultCredentialProvider ) ;
75
76
this . credentialsCache = new CredentialsCache ( this . defaultAwsAccount , defaultCredentialProvider ) ;
76
77
}
77
78
78
79
public async cloudFormation ( environment : Environment , mode : Mode ) : Promise < AWS . CloudFormation > {
79
80
return new AWS . CloudFormation ( {
80
81
region : environment . region ,
81
- credentials : await this . credentialsCache . get ( environment . account , mode ) ,
82
- ...this . defaultClientArgs
82
+ credentials : await this . credentialsCache . get ( environment . account , mode )
83
83
} ) ;
84
84
}
85
85
86
86
public async ec2 ( awsAccountId : string | undefined , region : string | undefined , mode : Mode ) : Promise < AWS . EC2 > {
87
87
return new AWS . EC2 ( {
88
88
region,
89
- credentials : await this . credentialsCache . get ( awsAccountId , mode ) ,
90
- ...this . defaultClientArgs
89
+ credentials : await this . credentialsCache . get ( awsAccountId , mode )
91
90
} ) ;
92
91
}
93
92
94
93
public async ssm ( awsAccountId : string | undefined , region : string | undefined , mode : Mode ) : Promise < AWS . SSM > {
95
94
return new AWS . SSM ( {
96
95
region,
97
- credentials : await this . credentialsCache . get ( awsAccountId , mode ) ,
98
- ...this . defaultClientArgs
96
+ credentials : await this . credentialsCache . get ( awsAccountId , mode )
99
97
} ) ;
100
98
}
101
99
102
100
public async s3 ( environment : Environment , mode : Mode ) : Promise < AWS . S3 > {
103
101
return new AWS . S3 ( {
104
102
region : environment . region ,
105
- credentials : await this . credentialsCache . get ( environment . account , mode ) ,
106
- ...this . defaultClientArgs
103
+ credentials : await this . credentialsCache . get ( environment . account , mode )
107
104
} ) ;
108
105
}
109
106
@@ -195,7 +192,7 @@ class DefaultAWSAccount {
195
192
private defaultAccountId ?: string = undefined ;
196
193
private readonly accountCache = new AccountAccessKeyCache ( ) ;
197
194
198
- constructor ( private readonly defaultCredentialsProvider : Promise < AWS . CredentialProviderChain > , private readonly defaultClientArgs : any ) {
195
+ constructor ( private readonly defaultCredentialsProvider : Promise < AWS . CredentialProviderChain > ) {
199
196
}
200
197
201
198
/**
@@ -223,7 +220,7 @@ class DefaultAWSAccount {
223
220
const accountId = await this . accountCache . fetch ( creds . accessKeyId , async ( ) => {
224
221
// if we don't have one, resolve from STS and store in cache.
225
222
debug ( 'Looking up default account ID from STS' ) ;
226
- const result = await new AWS . STS ( { credentials : creds , ... this . defaultClientArgs } ) . getCallerIdentity ( ) . promise ( ) ;
223
+ const result = await new AWS . STS ( { credentials : creds } ) . getCallerIdentity ( ) . promise ( ) ;
227
224
const aid = result . Account ;
228
225
if ( ! aid ) {
229
226
debug ( 'STS didn\'t return an account ID' ) ;
0 commit comments