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
a2d93048
Commit
a2d93048
authored
Sep 09, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
405f5e44
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
create.js
create.js
+17
-17
No files found.
create.js
View file @
a2d93048
...
...
@@ -34,25 +34,20 @@ function extractAWSCredentials(filePath) {
}
}
// Function to create
Lightsail instances
async
function
createLightsailInstance
s
(
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 instance
s
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
createLightsailInstance
s
(
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
}
...
...
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