Commit a2d93048 authored by Ahmad's avatar Ahmad

inikt

parent 405f5e44
......@@ -34,25 +34,20 @@ function extractAWSCredentials(filePath) {
}
}
// Function to create Lightsail instances
async function createLightsailInstances(lightsail, region, zone, count) {
// Function to create a single Lightsail instance
async function createLightsailInstance(lightsail, region, zone, instanceName) {
const instanceParams = {
blueprintId: 'ubuntu_20_04', // Ubuntu 20.04
bundleId: 'large_2_0', // $44 USD plan for Lightsail
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 {
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) {
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() {
// Define the regions and zones to create instances in
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
for (const { region, zone, count } of regionsAndZones) {
// Loop through each region and create one instance at a time
for (const { region, zone, instanceName } of regionsAndZones) {
const lightsail = new AWS.Lightsail({ region });
await createLightsailInstances(lightsail, region, zone, count);
console.log(`Waiting 30 seconds before creating instances in the next region...`);
await createLightsailInstance(lightsail, region, zone, instanceName);
console.log(`Waiting 30 seconds before creating the next instance...`);
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