Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aws
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
aws
Commits
9f7d4337
Commit
9f7d4337
authored
Aug 18, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
b7d3f278
Pipeline
#215
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
13 deletions
+49
-13
app.js
app.js
+49
-13
No files found.
app.js
View file @
9f7d4337
...
@@ -56,17 +56,62 @@ async function getLightsailInstances(region, credentials) {
...
@@ -56,17 +56,62 @@ async function getLightsailInstances(region, credentials) {
try
{
try
{
const
instances
=
await
lightsail
.
getInstances
({}).
promise
();
const
instances
=
await
lightsail
.
getInstances
({}).
promise
();
console
.
log
(
`Instances in
${
region
}
:`
,
instances
);
// Log full response for debugging
return
instances
.
instances
;
return
instances
.
instances
;
}
catch
(
err
)
{
}
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
[];
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
()
{
async
function
main
()
{
try
{
try
{
const
credentials
=
extractAWSCredentials
(
rootKeyFilePath
);
const
credentials
=
extractAWSCredentials
(
rootKeyFilePath
);
console
.
log
(
'
AWS Credentials Loaded:
'
,
credentials
);
// Log loaded credentials for debugging
console
.
log
(
'
AWS Credentials Loaded:
'
,
credentials
);
const
regions
=
getPemFilesAndRegions
();
const
regions
=
getPemFilesAndRegions
();
if
(
regions
.
length
===
0
)
{
if
(
regions
.
length
===
0
)
{
...
@@ -75,16 +120,7 @@ async function main() {
...
@@ -75,16 +120,7 @@ async function main() {
}
}
for
(
const
region
of
regions
)
{
for
(
const
region
of
regions
)
{
console
.
log
(
`Fetching instances in region:
${
region
}
`
);
await
processRegion
(
region
,
credentials
);
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
}
`
);
});
}
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
error
(
'
Error:
'
,
error
.
message
);
console
.
error
(
'
Error:
'
,
error
.
message
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment