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
1eef3fe2
Commit
1eef3fe2
authored
Nov 04, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
09035bd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
2 deletions
+29
-2
create.js
create.js
+29
-2
No files found.
create.js
View file @
1eef3fe2
...
...
@@ -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
const
sleep
=
(
ms
)
=>
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
ms
));
...
...
@@ -90,14 +109,22 @@ async function main() {
if
(
!
exists
)
{
console
.
log
(
`Instance
${
instanceName
}
does not exist in region
${
region
}
, creating...`
);
await
createLightsailInstance
(
lightsail
,
region
,
instanceName
);
console
.
log
(
`Waiting
3
0 seconds before creating the next instance...`
);
await
sleep
(
3
0000
);
// Wait for 60 seconds to avoid hitting rate limits
console
.
log
(
`Waiting
6
0 seconds before creating the next instance...`
);
await
sleep
(
6
0000
);
// Wait for 60 seconds to avoid hitting rate limits
}
else
{
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
'
);
}
catch
(
error
)
{
...
...
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