How to deploy on EC2 and connect to RDS - xujiahang11/LogpieShoppingTool GitHub Wiki

1. Create an RDS instance following its tutorial. Import your schema and data if necessary(can use MySQLWorkbench). In the security group, you need to change the inbound SSH traffic from your IP address to anyone:

   MySQL TCP 3306

2. Create an EC2 instance. Leave data tier blank. Choose default VPC and the security group associated with your RDS instance. You also set up the security group inbound traffic as following:

   HTTP TCP 80
   Custom TCP Rule TCP 8080
   SSH TCP 22

3. Use the chmod command to make sure that your private key file isn't publicly viewable:

   "chmod 400 /path/your-key-pair.pem"

4. Use the ssh command to connect to the instance. Then enter "yes".

   "ssh -i /path/your-key-pair.pem ec2-user@your-ec2-url"
   "sudo ssh -i /path/your-key-pair.pem your-ec2-url -l ec2-user"

5. Check Java version. Install Java if it doesn't exist: "sudo yum install java-1.8.0-openjdk". Then type "exit" to log out.

6. Use the scp command to transfer your .jar file(usually in .../build/libs) to the instance:

   "scp -i /path/your-key-pair.pem /path/LogpieShoppingTool-1.0.jar ec2-user@your-ec2-url:~"

7. Connect to the instance again. Use the nohup to run your service in background. On Linux ports below 1024 can be opened only by root, so the port 80 is restricted by default. If you want your server on port 80, you need use "sudo" and "--server.port=80" to specify.

   "sudo nohup java -jar LogpieShoppingTool-1.0.jar --server.port=80 &"

8. After everything is done, you could use DNSPOD to add A record(EC2 instance IP address) to your unique domain.

⚠️ ** Fallback** ⚠️