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


  1. Create an instance on EC2. You can use Amazon Linux 2 as the image


  2. 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


  3. Install Coretto 8 JDK


  4. Install Maven


  5. 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


  1. 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>



  2. 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 &



  3. You should now see the "Bot Connected" message in the channel



Updating the Appplication


  1. Find the Process ID (PID) of the currently running version
    • ps aux | egrep '[D]iscordBot'



  2. Kill the process
    • kill <PID>



  3. Deploy the new version using the above steps