Commit e3d794f6 authored by Ahmad's avatar Ahmad

inikt

parent 63b69039
...@@ -88,26 +88,18 @@ async function openAllPorts(lightsail, instanceName) { ...@@ -88,26 +88,18 @@ async function openAllPorts(lightsail, instanceName) {
}); });
}); });
} }
async function getAccountEmail(credentials) { async function getAccountId(credentials) {
const iam = new AWS.IAM({ const sts = new AWS.STS({
accessKeyId: credentials.accessKeyId, accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey, secretAccessKey: credentials.secretAccessKey,
}); });
try { try {
const accountSummary = await iam.getAccountSummary().promise(); const identity = await sts.getCallerIdentity().promise();
console.log('Account summary retrieved.'); console.log('AWS Account ID retrieved:', identity.Account);
return identity.Account; // This is the account ID
// 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.');
}
} catch (err) { } catch (err) {
console.error('Error fetching AWS account email:', err.message); console.error('Error fetching AWS Account ID:', err.message);
throw err; throw err;
} }
} }
...@@ -227,7 +219,7 @@ async function main() { ...@@ -227,7 +219,7 @@ async function main() {
try { try {
const credentials = extractAWSCredentials(rootKeyFilePath); const credentials = extractAWSCredentials(rootKeyFilePath);
console.log('AWS Credentials Loaded:', credentials); console.log('AWS Credentials Loaded:', credentials);
const accountEmail = await getAccountEmail(credentials); const accountEmail = await getAccountId(credentials);
console.log('AWS Account Email:', accountEmail); console.log('AWS Account Email:', accountEmail);
return return
const regions = getPemFilesAndRegions(); 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