2018 Modded Minecraft Server on AWS : Part 1 — Run a modded Minecraft server on AWS EC2 instance

Andrew WC Brown
ExamPro
Published in
7 min readAug 18, 2018

Store Forge and Modpack on S3

When we launch our server we’re going to need to copy over the following:

  • forge-installer
  • our modpack
  • a script to run forge in the background

Go and create an S3 Bucket and name it whatever you like. S3 buckets are global so the name will have to be unique just like your hotmail account.

Click into that bucket and create a folder called setup

Download the Forge Installer 1.12.2 and upload the .jar to your setup folder.

Next download the Twitch Desktop Client and go to Mods > Minecraft and create a custom profile

You need to have Minecraft Installed already to have it show up under Mods tab

Name your profile whatever you like

Click into you newly created profile and lets install a mod

Lets install the Journey Map which adds a map to our HUD.

Other great options to install are Familiar Fauna or Biomes O’ Plenty

Lets Play locally to ensure that our mod is working as expected

You’ll see the Forge loader and it will give you an idea by that little vertical red line how much memory was required just to load the mod.

Loading up a game we can see the Journey Map mod working.

Next we’re going to want to open the folder to get to the mods, zip our mods folder and upload that to S3 to our setup folder

create and upload to s3 a filed called minecraft.service with the following:

[Unit]
Description=Minecraft Service
After=default.target
[Service]
Type=simple
User=ec2-user
ExecStart=/usr/bin/java -jar /minecraft/forge-1.12.2-14.23.4.2756-universal.jar

Create a Policy and Role so EC2 can access S3

Our EC2 is going to need a way to access our S3 bucket. We could give our EC2 full access to S3 but lets do it right by creating a new policy that only allows the required permissions to read, write and delete to only the bucket we’re using.

So create a new Policy under IAM and use the following and remember to substitute your bucket name.

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:ListBucket"],
"Resource": ["arn:aws:s3:::<BUCKET-NAME>"]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetObject",
"s3:GetBucketLocation",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:DeleteObject"
],
"Resource": ["arn:aws:s3:::<BUCKET-NAME>/*"]
}
]
}

I name my policies using snake-case so I can quickly distinguish them easily from predefined policies

Lets go and create a new role for EC2 with our new policy

We now have everything and proceed with creating our server

Configure and Launch an EC2 Instance

The big difference between a vanilla and modded Minecraft server is the latter requires significant ram to run smoothly. We’re going to want to have at least 4 GB of RAM.

Lets launch a new EC2 Instance

From the EC2 Dashboard Launch a new Instance

For our Machine Image we’re going to choose Amazon Linux 2 AMI because newer usually means better.

For our instance type we want at least 4 GB of memory so t2.medium will meet our needs.

Installing Java and setting up our directories with UserData

#!/usr/bin/env bash
sudo yum -y install java-1.8.0
sudo mkdir /minecraft
sudo chown -R ec2-user:ec2-user /minecraft
cd /minecraft
aws s3 cp s3://minecraft-server00/setup/forge-1.12.2-14.23.4.2756-installer.jar /minecraft/forge-1.12.2-14.23.4.2756-installer.jar
java -jar forge-1.12.2-14.23.4.2756-installer.jar --installServer
echo '#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).
#Mon Aug 06 18:11:14 UTC 2018
eula=true' > eula.txt
aws s3 cp s3://minecraft-server00/setup/mods.zip /minecraft/mods.zip
unzip mods.zip
sudo aws s3 cp s3://minecraft-server00/setup/minecraft.service /etc/systemd/system/minecraft.service
sudo systemctl daemon-reload
sudo service minecraft start

We need to create a new security group to permit traffic for both TCP and UDP on port 25565 from Anywhere. Also its good practice that we only restrict SSH access to only our IP.

On the review screen you’ll see warning which makes sense since we deliberately expose port 25565 to anyone and we should expect to see that this service is not part of the free tier.

We need to create a key/pair for this server and download somewhere such as your Documents directory. We can’t recover this key later so its best not to lose it. This key is needed when we want to ssh into our server.

You may have to upto 5 mins for you server to start and you may need to refresh the page. We’re waiting until both status checks are 2/2 and the Instance State is running. I would also give your server a few minutes to create the world and load the mods.

Take that public IP and add a new server

And if everything works out then you should be in the green. Remember to give your server some time to create the world and load the mods.

Debugging

Things that can go wrong is the UserData installation script fails to do something or something happened when the Minecraft service launched. You can SSH your server and check by getting your public DNS address for the server.

How to SSH into your server

Then using that keypair you safely stored on your computer you can ssh into your server.

ssh -i ~/Documents/aws-keys/minecraft.pem ec2-user@<PUBLIC-DNS>

Check Minecraft Service for Problems

We can check to see if its running, we can and then start it.

sudo service minecraft status
sudo service minecraft stop
sudo service minecraft start

we can check the service logs for any possible errors.

journalctl -u minecraft

Check Cloud Init Logs

Cloud Init is what runs the UserData bash script and can reveal if something failed.

tail -n 500 /var/log/cloud-init-output.log

Run the UserData Script On the Server

If you suspect the the script did not run at all you can run try running it on the server if an error occurs

sudo bash /var/lib/cloud/instances/<INSTANCE-ID>/user-data.txt

alternatively you can run each line at a time for granular debugging

Change UserData Script

If you need to update your UserData script you can stop your instance, update it and then start the server. When you stop an EC2 instance it will wipe all the data which is much less work than Terminating and creating a new instance.

--

--

Andrew WC Brown
ExamPro

I have an unhealthy obsession with web-development.