generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAwsClient.ts
More file actions
33 lines (28 loc) · 1.11 KB
/
AwsClient.ts
File metadata and controls
33 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { CloudControlClient } from '@aws-sdk/client-cloudcontrol';
import { CloudFormationClient } from '@aws-sdk/client-cloudformation';
import { AwsCredentials } from '../auth/AwsCredentials';
import { IamCredentials } from '../auth/AwsLspAuthTypes';
import { ExtensionId, ExtensionVersion } from '../utils/ExtensionConfig';
type IamClientConfig = {
region: string;
credentials: IamCredentials;
customUserAgent: string;
};
export class AwsClient {
constructor(private readonly credentialsProvider: AwsCredentials) {}
// By default, clients will retry on throttling exceptions 3 times
public getCloudFormationClient() {
return new CloudFormationClient(this.iamClientConfig());
}
public getCloudControlClient() {
return new CloudControlClient(this.iamClientConfig());
}
private iamClientConfig(): IamClientConfig {
const credential = this.credentialsProvider.getIAM();
return {
region: credential.region,
credentials: this.credentialsProvider.getIAM(),
customUserAgent: `${ExtensionId}/${ExtensionVersion}`,
};
}
}