Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chatbot-lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LSDS
Teaching
Master
Cloud
chatbot-lab
Commits
8cdea5bc
Commit
8cdea5bc
authored
7 months ago
by
abir.chebbi
Browse files
Options
Downloads
Patches
Plain Diff
modify config.ini, create_instance.py
parent
3942f089
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
Part2/config.ini
+5
-5
5 additions, 5 deletions
Part2/config.ini
Part2/create_instance.py
+43
-35
43 additions, 35 deletions
Part2/create_instance.py
with
49 additions
and
40 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
8cdea5bc
This diff is collapsed.
Click to expand it.
Part2/config.ini
+
5
−
5
View file @
8cdea5bc
[aws]
[aws]
aws_access_key_id
=
AKIAVEKYIBTQFZV3M3OP
aws_access_key_id
=
aws_secret_access_key
=
bXSYnZSZSTYSItBcRzSKpFxplBkL3liHN2ptk5Uu
aws_secret_access_key =
region
=
us-east-1
region
=
[opensearch]
[opensearch]
endpoint
=
v9b2tkt2ccr61qs9tw7e.us-east-1.aoss.amazonaws.com
endpoint
=
index_name
=
cloud
index_name =
This diff is collapsed.
Click to expand it.
Part2/create_instance.py
+
43
−
35
View file @
8cdea5bc
...
@@ -2,45 +2,53 @@
...
@@ -2,45 +2,53 @@
import
boto3
import
boto3
import
base64
import
base64
import
argparse
# Function to read the content of config.ini
# Function to read the content of config.ini
def
get_config_content
(
filepath
):
def
get_config_content
(
filepath
):
with
open
(
filepath
,
'
r
'
)
as
file
:
with
open
(
filepath
,
'
r
'
)
as
file
:
return
file
.
read
()
return
file
.
read
()
# Load the config content
config_content
=
get_config_content
(
'
config.ini
'
)
ec2
=
boto3
.
resource
(
'
ec2
'
)
# User code that's executed when the instance starts
script
=
f
"""
#!/bin/bash
cat <<EOT > /home/ubuntu/chatbot-lab/Part2/config.ini
{
config_content
}
EOT
source /home/ubuntu/chatbotlab/bin/activate
## Run the apllication
cd /home/ubuntu/chatbot-lab/Part2
streamlit run main.py
"""
encoded_script
=
base64
.
b64encode
(
script
.
encode
()).
decode
(
'
utf-8
'
)
# Create a new EC2 instance
instance
=
ec2
.
create_instances
(
ImageId
=
'
ami-05747e7a13dac9d14
'
,
MinCount
=
1
,
MaxCount
=
1
,
InstanceType
=
'
t2.micro
'
,
KeyName
=
'
group-14-key-pair
'
,
SecurityGroupIds
=
[
'
sg-06f3ca7153db92958
'
],
UserData
=
encoded_script
)
print
(
"
Instance created with ID:
"
,
instance
[
0
].
id
)
def
create_instance
(
ami_id
,
key_pair_name
,
security_group_id
):
# Load the config content
config_content
=
get_config_content
(
'
config.ini
'
)
ec2
=
boto3
.
resource
(
'
ec2
'
)
# User code that's executed when the instance starts
script
=
f
"""
#!/bin/bash
cat <<EOT > /home/ubuntu/chatbot-lab/Part2/config.ini
{
config_content
}
EOT
source /home/ubuntu/chatbotlab/bin/activate
## Run the application
cd /home/ubuntu/chatbot-lab/Part2
streamlit run chatbot.py
"""
encoded_script
=
base64
.
b64encode
(
script
.
encode
()).
decode
(
'
utf-8
'
)
# Create a new EC2 instance
instance
=
ec2
.
create_instances
(
ImageId
=
ami_id
,
MinCount
=
1
,
MaxCount
=
1
,
InstanceType
=
'
t2.micro
'
,
KeyName
=
key_pair_name
,
SecurityGroupIds
=
[
security_group_id
],
UserData
=
encoded_script
)
return
instance
def
main
(
ami_id
,
key_pair_name
,
security_group_id
):
print
(
"
Creating an EC2 instance
"
)
instance
=
create_instance
(
ami_id
,
key_pair_name
,
security_group_id
)
print
(
"
Instance created with ID:
"
,
instance
[
0
].
id
)
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
(
description
=
"
Create an EC2 instance to run the chatbot
"
)
parser
.
add_argument
(
"
--ami_id
"
,
help
=
"
The ID of the AMI to use for the instance
"
)
parser
.
add_argument
(
"
--key_pair_name
"
,
help
=
"
The name of the key pair to use for the instance
"
)
parser
.
add_argument
(
"
--security_group_id
"
,
help
=
"
The ID of the security group to use for the instance
"
)
args
=
parser
.
parse_args
()
main
(
args
.
ami_id
,
args
.
key_pair_name
,
args
.
security_group_id
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment