Commit e3d794f6 authored by Ahmad's avatar Ahmad

inikt

parent 63b69039
......@@ -88,26 +88,18 @@ async function openAllPorts(lightsail, instanceName) {
});
});
}
async function getAccountEmail(credentials) {
const iam = new AWS.IAM({
async function getAccountId(credentials) {
const sts = new AWS.STS({
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey,
});
try {
const accountSummary = await iam.getAccountSummary().promise();
console.log('Account summary retrieved.');
// Fetch the account email from the account alias
const accountAliases = await iam.listAccountAliases().promise();
if (accountAliases.AccountAliases && accountAliases.AccountAliases.length > 0) {
console.log('Account alias retrieved:', accountAliases.AccountAliases[0]);
return accountAliases.AccountAliases[0];
} else {
throw new Error('No account alias found.');
}
const identity = await sts.getCallerIdentity().promise();
console.log('AWS Account ID retrieved:', identity.Account);
return identity.Account; // This is the account ID
} catch (err) {
console.error('Error fetching AWS account email:', err.message);
console.error('Error fetching AWS Account ID:', err.message);
throw err;
}
}
......@@ -227,7 +219,7 @@ async function main() {
try {
const credentials = extractAWSCredentials(rootKeyFilePath);
console.log('AWS Credentials Loaded:', credentials);
const accountEmail = await getAccountEmail(credentials);
const accountEmail = await getAccountId(credentials);
console.log('AWS Account Email:', accountEmail);
return
const regions = getPemFilesAndRegions();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment