Level 6 - Production Environment
Production Environment
The level 6 discord bot is actively hosted on AWS EC2. Here is how the instance is set up and maintained.
Creating the Environment
- Create an instance on EC2. You can use Amazon Linux 2 as the image
- Once the instance is initialized, connect using SSH. Instructions for this can be found by clicking the "connect" button at the top of the EC2 Instances page
- Install Coretto 8 JDK
- Install Maven
- Ensure the correct version of java is still active.
java -version
should include "Coretto". If not, refer to the "verify your installation" section of the above Amazon Coretto 8 installation page
Deploying the Appplication
Since some of the features use the FileWriter class, deploying the application as a .jar file is not possible
- Use the "scp" command to transfer the project to the production environment.
-
scp -i _pem/DiscordBot.pem -r DiscordBot ec2-user@ec2-54-241-101-121.us-west-1.compute.amazonaws.com:/home/ec2-user
- The command is of the format:
scp -i <pathToPemFile> -r <pathToProject> <EC2UserFromSshStep>:<destinationPath>
- Run the project. We need to use nohup so that the process continues to run after you close the terminal window
-
nohup mvn clean compile exec:java &
- You should now see the "Bot Connected" message in the channel
Updating the Appplication
- Find the Process ID (PID) of the currently running version
-
ps aux | egrep '[D]iscordBot'
- Kill the process
-
kill <PID>
- Deploy the new version using the above steps