Before following further instructions, make sure you have tried running the Python Bot locally first. You also need to have an AWS account before deploying.
Provides free services for light usage for 1 year (AWS Free Tier). It is very flexible and suitable for more complex projects. Open the link to register.
The following are the steps to use AWS EC2 and run Python source code from GitHub on that server. Make sure you have an AWS account and are logged in.
Note: We will use the Free Tier only.
-
Open the AWS Management Console.
-
Navigate to the EC2 service by searching for it in the Services menu (next to the AWS logo).
-
Click Launch Instance.
-
Configure Instance:
-
Name the instance (e.g.
MyPythonServer
). -
Select an Amazon Machine Image (AMI):
- Select Ubuntu Server 22.04 LTS (HVM), SSD Volume Type.
-
Select an Instance Type:
- Select t2.micro.
-
-
Configure Key Pair:
-
Create a new key pair by pressing Create new key pair.
-
Give it a name, for example
my-key-pair
. -
Choose the key file format:
-
If you are going to connect with OpenSSH, choose
.pem
. -
If you will connect with PuTTY (for Windows), select
.ppk
.
-
-
Save the file by pressing Create key pair.
-
-
Configure Network Settings:
- Check Allow SSH traffic from and change it to My IP (for security) or leave it as Anywhere
0.0.0.0/0
(to be accessible from anywhere). Avoid selecting0.0.0.0/0
(access from all IPs), unless absolutely necessary.
- Check Allow SSH traffic from and change it to My IP (for security) or leave it as Anywhere
-
Configure Storage:
- Ensure that the storage allocation is sufficient for your project needs. 8 GB is usually enough for small applications.
-
(Optional) Install dependencies (
pip install
for Python scripts). In the Advanced Details section, find User Data (for bootstrapping) and add the code below in the input field.#!/bin/bash sudo apt-get update sudo apt-get install -y python3-pip pip3 install -r /home/ubuntu/requirements.txt
-
Click Launch Instance.
-
Navigate to the Instances tab in the EC2 Console and select your instance, click the Connect button, select the SSH client menu. Copy the SSH command example.
-
Open a terminal on your computer and access the instance using SSH, paste the SSH command above.
-
Change the location of the
.pem
file according to the location of the file you saved. -
If there is an error regarding permissions, run command below.
chmod 400 /path/to/my-key-pair.pem
Then try making a connection again using SSH.
-
-
(Optional) If an error occurs while making the connection and you are tired, please use CloudShell which is located in the bottom left corner or in the top menu with the console icon next to the bell icon. Keep in mind that CloudShell is a temporary environment. All running processes will be terminated once you close your CloudShell session or exit the AWS Console.
-
Check Python, Pip and Git versions. Execute per 1 line.
python3 --version pip --version git --version
-
If an error occurs in number 1 then update the package list and install the missing package.
sudo apt update -y # Install according to the error package sudo apt install python3 -y sudo apt install python3-pip -y sudo apt install git -y
-
Check the installed package version again as in number 1.
-
Clone GitHub repository.
git clone https://github.com/syauqi-a/GetGrassMiner.git
-
Go to project folder.
cd GetGrassMiner
It is recommended to still create virtual environment.
-
(Optional) If the
virtualenv
package does not exist, install it first:sudo pip3 install virtualenv
-
Create and activate virtual environment:
python3 -m venv venv source venv/bin/activate
-
Install dependencies from the
requirements.txt
file.pip install -r requirements.txt
Make configuration settings in the .env
, config.json
and proxies.txt
files as when running locally, see here.
Run the main script to start the bot.
python main.py
If you want the application to keep running even if you exit SSH, use the following method:
nohup python main.py > /dev/null 2>&1 & echo $! > nohup_main.pid
Note:
-
By adding
> /dev/null 2>&1
all standard output (stdout
) and error output (stderr
) will not be saved to prevent storage bloat. -
See
main.py
process running in the background.ps -ef | grep main.py
-
See the process in more detail.
htop
Then press F4, enter
main.py
and press ENTER. To exit press Q. -
Terminates the
main.py
process running in the background.kill $(cat nohup_main.pid)