Commit 9f7d4337 authored by Ahmad's avatar Ahmad

inikt

parent b7d3f278
Pipeline #215 canceled with stages
......@@ -56,17 +56,62 @@ async function getLightsailInstances(region, credentials) {
try {
const instances = await lightsail.getInstances({}).promise();
console.log(`Instances in ${region}:`, instances); // Log full response for debugging
return instances.instances;
} catch (err) {
console.error(`Error fetching instances in region ${region}:`, err); // Log full error object
console.error(`Error fetching instances in region ${region}:`, err.message);
return [];
}
}
async function openAllPorts(lightsail, instanceName) {
const params = {
instanceName: instanceName,
portInfos: [
{
fromPort: 0,
protocol: 'all',
toPort: 65535
},
]
};
return new Promise((resolve, reject) => {
lightsail.putInstancePublicPorts(params, (err, data) => {
if (err) {
console.error(`Error opening ports for instance ${instanceName}:`, err);
reject(err);
} else {
console.log(`Ports opened for instance ${instanceName}`);
resolve(data);
}
});
});
}
async function processRegion(region, credentials) {
const lightsail = new AWS.Lightsail({
region,
accessKeyId: credentials.accessKeyId,
secretAccessKey: credentials.secretAccessKey
});
console.log(`Fetching instances in region: ${region}`);
const instances = await getLightsailInstances(region, credentials);
if (instances.length === 0) {
console.log(`No instances found in region: ${region}`);
} else {
for (const instance of instances) {
console.log(`Processing instance: ${instance.name} in region: ${region}`);
await openAllPorts(lightsail, instance.name);
}
}
}
async function main() {
try {
const credentials = extractAWSCredentials(rootKeyFilePath);
console.log('AWS Credentials Loaded:', credentials); // Log loaded credentials for debugging
console.log('AWS Credentials Loaded:', credentials);
const regions = getPemFilesAndRegions();
if (regions.length === 0) {
......@@ -75,16 +120,7 @@ async function main() {
}
for (const region of regions) {
console.log(`Fetching instances in region: ${region}`);
const instances = await getLightsailInstances(region, credentials);
if (instances.length === 0) {
console.log(`No instances found in region: ${region}`);
} else {
instances.forEach(instance => {
console.log(`- Instance Name: ${instance.name}, State: ${instance.state.name}`);
});
}
await processRegion(region, credentials);
}
} catch (error) {
console.error('Error:', error.message);
......
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