@cloud-copilot/iam-collect
Version:
Collect IAM information from AWS Accounts
22 lines • 804 B
JavaScript
import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
/**
* Get the AWS account ID and partition from the provided credentials.
*
* @param credentials The AWS credentials to use for the request.
* @returns An object containing the AWS account ID and partition for the provided credentials.
*/
export async function getTokenInfo(credentials) {
const stsClient = new STSClient({ credentials });
const command = new GetCallerIdentityCommand({});
const response = await stsClient.send(command);
const accountId = response.Account;
const arn = response.Arn;
const arnParts = arn.split(':');
const partition = arnParts[1];
return {
accountId: accountId,
partition: partition,
arn: arn
};
}
//# sourceMappingURL=tokens.js.map