-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetAWSInfo.ts
More file actions
36 lines (29 loc) · 835 Bytes
/
getAWSInfo.ts
File metadata and controls
36 lines (29 loc) · 835 Bytes
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
34
35
36
import {
STSClient,
GetCallerIdentityCommand
} from '@aws-sdk/client-sts';
import {
IAMClient,
ListAccountAliasesCommand
} from '@aws-sdk/client-iam';
import {
AWSConfig,
AWSInfo
} from './types';
export default async function getAWSInfo(awsConfig: AWSConfig): Promise<AWSInfo> {
const stsClient = new STSClient(awsConfig);
const { Account: accountId, Arn: userArn } = await stsClient.send(
new GetCallerIdentityCommand({})
);
const iamClient = new IAMClient(awsConfig);
const { AccountAliases: aliases } = await iamClient.send(
new ListAccountAliasesCommand({})
);
return {
accountId: accountId as string,
partition: (userArn as string).split(':')[1],
userArn: userArn as string,
region: await stsClient.config.region(),
accountAlias: aliases ? aliases[0] : undefined
}
}