Commit 1eef3fe2 authored by Ahmad's avatar Ahmad

inikt

parent 09035bd8
...@@ -62,6 +62,25 @@ async function createLightsailInstance(lightsail, region, instanceName) { ...@@ -62,6 +62,25 @@ async function createLightsailInstance(lightsail, region, instanceName) {
} }
} }
// Function to download Lightsail default SSH key for each region
async function downloadSSHKey(region) {
const keyFilePath = path.join(downloadsPath, `LightsailDefaultKey-${region}.pem`);
const lightsail = new AWS.Lightsail({ region });
try {
const keyData = await lightsail.getKeyPair({ keyPairName: `LightsailDefaultKey-${region}` }).promise();
fs.writeFileSync(keyFilePath, keyData.keyMaterial, { mode: 0o600 }); // Write the key with proper permissions
console.log(`Downloaded SSH key for region ${region}`);
return keyFilePath;
} catch (error) {
console.error(`Failed to download SSH key for region ${region}:`, error.message);
return null;
}
}
// Function to SSH into instance to validate SSH key
// Function to add delay // Function to add delay
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
...@@ -90,14 +109,22 @@ async function main() { ...@@ -90,14 +109,22 @@ async function main() {
if (!exists) { if (!exists) {
console.log(`Instance ${instanceName} does not exist in region ${region}, creating...`); console.log(`Instance ${instanceName} does not exist in region ${region}, creating...`);
await createLightsailInstance(lightsail, region, instanceName); await createLightsailInstance(lightsail, region, instanceName);
console.log(`Waiting 30 seconds before creating the next instance...`); console.log(`Waiting 60 seconds before creating the next instance...`);
await sleep(30000); // Wait for 60 seconds to avoid hitting rate limits await sleep(60000); // Wait for 60 seconds to avoid hitting rate limits
} else { } else {
console.log(`Instance ${instanceName} already exists in region ${region}, skipping creation.`); console.log(`Instance ${instanceName} already exists in region ${region}, skipping creation.`);
} }
} }
} }
// Download and verify SSH keys for all regions after creating instances
for (const region of regions) {
const keyFilePath = await downloadSSHKey(region);
}
console.log('All Done'); console.log('All Done');
} catch (error) { } catch (error) {
......
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