Commit a2d93048 authored by Ahmad's avatar Ahmad

inikt

parent 405f5e44
...@@ -34,25 +34,20 @@ function extractAWSCredentials(filePath) { ...@@ -34,25 +34,20 @@ function extractAWSCredentials(filePath) {
} }
} }
// Function to create Lightsail instances // Function to create a single Lightsail instance
async function createLightsailInstances(lightsail, region, zone, count) { async function createLightsailInstance(lightsail, region, zone, instanceName) {
const instanceParams = { const instanceParams = {
blueprintId: 'ubuntu_20_04', // Ubuntu 20.04 blueprintId: 'ubuntu_20_04', // Ubuntu 20.04
bundleId: 'large_2_0', // $44 USD plan for Lightsail bundleId: 'large_2_0', // $44 USD plan for Lightsail
availabilityZone: `${region}a`, // Availability zone (usually 'a', 'b', or 'c') availabilityZone: `${region}a`, // Availability zone (usually 'a', 'b', or 'c')
instanceNames: [], // Will be populated below instanceNames: [instanceName], // Only creating one instance at a time
}; };
// Create instances with names Ubuntu-1, Ubuntu-2, etc.
for (let i = 1; i <= count; i++) {
instanceParams.instanceNames.push(`Ubuntu-${i}`);
}
try { try {
const result = await lightsail.createInstances(instanceParams).promise(); const result = await lightsail.createInstances(instanceParams).promise();
console.log(`Created ${count} instances in region ${region}, zone ${zone}:`, result); console.log(`Created instance ${instanceName} in region ${region}, zone ${zone}:`, result);
} catch (error) { } catch (error) {
console.error(`Failed to create instances in ${region}:`, error.message); console.error(`Failed to create instance ${instanceName} in ${region}:`, error.message);
} }
} }
...@@ -73,16 +68,21 @@ async function main() { ...@@ -73,16 +68,21 @@ async function main() {
// Define the regions and zones to create instances in // Define the regions and zones to create instances in
const regionsAndZones = [ const regionsAndZones = [
{ region: 'us-west-2', zone: 'Oregon', count: 2 },
{ region: 'us-east-2', zone: 'Ohio', count: 2 },
{ region: 'us-east-1', zone: 'Virginia', count: 2 }, { region: 'us-east-2', zone: 'Ohio', instanceName: 'Ubuntu-1' },
{ region: 'us-west-2', zone: 'Oregon', instanceName: 'Ubuntu-1' },
{ region: 'us-east-1', zone: 'Virginia', instanceName: 'Ubuntu-1' },
{ region: 'us-east-2', zone: 'Ohio', instanceName: 'Ubuntu-2' },
{ region: 'us-west-2', zone: 'Oregon', instanceName: 'Ubuntu-2' },
{ region: 'us-east-1', zone: 'Virginia', instanceName: 'Ubuntu-2' },
]; ];
// Loop through each region and zone to create instances // Loop through each region and create one instance at a time
for (const { region, zone, count } of regionsAndZones) { for (const { region, zone, instanceName } of regionsAndZones) {
const lightsail = new AWS.Lightsail({ region }); const lightsail = new AWS.Lightsail({ region });
await createLightsailInstances(lightsail, region, zone, count); await createLightsailInstance(lightsail, region, zone, instanceName);
console.log(`Waiting 30 seconds before creating instances in the next region...`); console.log(`Waiting 30 seconds before creating the next instance...`);
await sleep(30000); // Wait for 30 seconds await sleep(30000); // Wait for 30 seconds
} }
......
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