This content originally appeared on DEV Community and was authored by carmen
Hosting your own Minecraft server is one of the best ways to enjoy the game with friends, explore custom worlds, or add plugins that make the experience unique. In this guide, we’ll walk through how to set up a fully functional Minecraft server on Amazon Web Services (AWS) using EC2. By the end, you’ll have a server that starts automatically, uses a static IP so players can always connect, and can be customized with plugins or new worlds, all while keeping costs under control.
Step 1: Set up the Server (EC2 Instance)
- Log in to AWS Management Console.
-
Choose a region: In the top-right corner, select the AWS region closest to your players.
Example: If most players are on the US West Coast, select one of the us-west regions.
Open the EC2 service: Search for EC2 in the console search bar and open the dashboard.
Launch a new instance: Click on Launch instance.
-
Configure the instance:
- Give the instance a descriptive name, such as “Minecraft Server”.
- Choose Amazon Linux 2023 AMI.
- Set the architecture to 64-bit (Arm).
-
Select the instance type:
- Start with t4g.small, which is enough for a basic Minecraft server (it’s fine for a few players, but laggy with mods or >5 players. If you expect more, go to t4g.medium or larger).
- If you need more performance later, you can resize/upgrade the instance.
- For compute-intensive workloads, consider using the C family (Compute Optimized) instances.
-
Create a Key Pair:
- Under Key pair name, click Create a new key pair.
- Enter a name for the key (e.g., minecraft-key).
- Click Create a key pair.
- The private key file (
.pem
) will be automatically downloaded to your computer. Keep this file safe (you will need it later if you want to connect to the server).
-
Configure Network Settings:
- Scroll down to the Network settings section and click Edit.
- Select the default VPC. Leave the subnet as No preference.
- Make sure Auto-assign public IP is enabled.
- Under Firewall (security groups):
- Choose Create security group.
- Name it something like Minecraft Server SG.
- (Optional) Add a description such as: Security group for Minecraft Server. Ports open for SSH (22) and Minecraft TCP (25565).
-
Add inbound rules:
-
SSH access (EC2 Instance Connect):
- By default, SSH (port 22) is enabled, but you must restrict it to the correct IP range for EC2 Instance Connect in you AWS region.
- Find the correct CIDR range in the AWS IP address ranges documentation.
- For example, in the
eu-west-3
(Paris) region, the IP CIDR range is:35.180.112.80/29
. -
In Inbound rules, edit the SSH rule and set Source Custom, then paste the correct IP range for your region.
💡 Tip: To find the IP CIDR, download the JSON file from the documentation, open it in your browser as raw data, and search (Control+F) for
EC2_INSTANCE_CONNECT
.
-
Minecraft traffic: Add another inbound rule:
- Type: Custom TCP.
- Port Range: 25565.
- Source: 0.0.0.0/0 (to allow players to connect).
-
-
Add Storage:
- By default your instance comes with an 8 GB gp3 root volume, which is enough for a small server.
- If you expect more data (e.g., larger worlds, mods, or backups), you may increase the size here.
- AWS Free Tier includes up to 30GB of Elastic Block Storage (EBS), so you can expand the volume without leaving the free tier (as long as you stay under the 30GB).
Step 2: Set up Minecraft Automatically
- Add a startup script: We’ll use a bash script so that the Minecraft server is automatically downloaded, configured and started every time the EC2 instance launches.
-
Locate the User Data field:
- Scroll down to the Advanced Details section.
- Expand it, then scroll to the bottom to find the User data field.
-
Copy and paste the following script into that field:
#!/bin/bash set -euo pipefail # ===== CONFIG ===== # Replace with the latest server .jar URL from the official page MINECRAFT_URL="https://piston-data.mojang.com/v1/objects/6bce4ef400e4efaa63a13d5e6f6b500be969ef81/server.jar" MINECRAFT_DIR="/opt/minecraft/server" MINECRAFT_USER="minecraft" SERVICE_NAME="minecraft" # ===== PREREQS ===== # Install Java (Amazon Corretto) sudo yum install -y java-21-amazon-corretto-headless # Create a dedicated user and directories id -u "$MC_USER" >/dev/null 2>&1 || useradd --system --create-home --shell /sbin/nologin "$MC_USER" mkdir -p "$MC_DIR" cd "$MC_DIR" # ===== DOWNLOAD SERVER ===== # Download the Minecraft server JAR from the URL # (Overwrites existing server.jar if present) wget -O server.jar "$MINECRAFT_URL" # ===== FIRST BOOT TO GENERATE FILES ===== # Run once to create eula.txt and default configs (ignore non-zero exit) java -Xmx1024M -Xms1024M -jar server.jar nogui || true # Accept EULA sed -i 's/false/true/p' eula.txt # ===== CALCULATE HEAP SIZE FROM TOTAL RAM ===== # Use ~50% of total memory, clamp to [1024, 16384] MB, round down to nearest 256 MB TOTAL_MEM_MB=$(awk '/MemTotal/ {printf "%.0f", $2/1024}' /proc/meminfo) XMX_MB=$(( TOTAL_MEM_MB / 2 )) if [ "$XMX_MB" -lt 1024 ]; then XMX_MB=1024; fi if [ "$XMX_MB" -gt 16384 ]; then XMX_MB=16384; fi XMX_MB=$(( (XMX_MB/256)*256 )) # ===== START/STOP SCRIPTS ===== # Create start script cat > start <<'EOF' #!/bin/bash set -euo pipefail MC_DIR="/opt/minecraft/server" cd "$MC_DIR" # Recompute heap on each start (handles instance type changes) TOTAL_MEM_MB=$(awk '/MemTotal/ {printf "%.0f", $2/1024}' /proc/meminfo) XMX_MB=$(( TOTAL_MEM_MB / 2 )) if [ "$XMX_MB" -lt 1024 ]; then XMX_MB=1024; fi if [ "$XMX_MB" -gt 16384 ]; then XMX_MB=16384; fi XMX_MB=$(( (XMX_MB/256)*256 )) ulimit -n 4096 exec java -Xmx${XMX_MB}M -Xms${XMX_MB}M -jar server.jar nogui EOF chmod +x start # Create stop script cat > stop <<'EOF' #!/bin/bash # Graceful stop via systemd is preferred: systemctl stop minecraft # Fallback: kill Java owned by the minecraft user running the server.jar pkill -u minecraft -f 'java .*server\.jar' || true EOF chmod +x stop # Permissions chown -R "$MC_USER":"$MC_USER" /opt/minecraft # ===== SYSTEMD SERVICE ===== # Create a systemd service to run Minecraft on startup cat << 'EOF' > /etc/systemd/system/minecraft.service [Unit] Description=Minecraft Server Wants=network-online.target After=network-online.target [Service] User=${MC_USER} WorkingDirectory=${MC_DIR} ExecStart=${MC_DIR}/start ExecStop=${MC_DIR}/stop Restart=on-failure RestartSec=15 NoNewPrivileges=true ProtectSystem=full ProtectHome=true PrivateTmp=true [Install] WantedBy=multi-user.target EOF # Enable and start the service systemctl daemon-reload systemctl enable ${SERVICE_NAME}.service systemctl start ${SERVICE_NAME}.service
-
Get the latest Minecraft server link:
- To ensure you’re running the newest version, go to the official Minecraft Server download page.
- Find the link to “Download minecraft_server.jar”.
- Right-click the minecraft_server.jar link and copy the URL.
-
Replace the value of
MINECRAFT_URL
in the script above with this new link.
-
Launch the instance:
- Once you’ve added the script, click Launch Instance.
-
The EC2 instance may take 5-10 minutes on first boot while it installs dependencies and sets up the server.
🧪 Test: After the instance finishes launching, copy its public IPv4 address from the EC2 console. Open Minecraft, go to Multiplayer, add a new server, and paste the IP address. Within a few minutes, you should be able to connect to your new Minecraft server.
Step 3: Set Up Static IP
Every time an EC2 instance turns off, its public IP address will change. Having to search for your new IP every time you turn your server on and off is inefficient. We will associate an Elastic IP with our EC2 instance to solve this problem. Elastic IP addresses are dedicated IP addresses that do not change and can be attached to different resources.
-
Open Elastic IPs:
-
Allocate an Elastic IP:
-
Name the IP: To keep things organized, rename the Elastic IP to something descriptive, like Minecraft Server IP.
-
Associate the Elastic IP with the instance:
- Select the new Elastic IP.
-
Click Actions → Associate Elastic IP Address.
For Resource type, choose Instance.
From the drop-down list, select the Minecraft EC2 instance we created before.
Click Associate.
-
Verify the Elastic IP:
- Go back to the Minecraft EC2 instance details.
- Under Public IPv4 address, we should now see the Elastic IP.
-
Connect to the server in Minecraft:
- Open Minecraft and go to the Multiplayer screen.
- Click Add Server (or use Direct Connect).
- In the Server Address field, enter the Elastic IP.
- The server should now be accessible with the static IP every time you restart the instance.
⚠️ Warning: Elastic IPs are free **as long as they are attached to a running instance. If you allocate one but don’t associate it with anything, AWS may charge you a small hourly fee.
Extra: Customize the Server (Plugins, World Files, etc.)
Once the server is up and running, you may want to install plugins, change the world, or modify configuration files. To do that, you’ll need to connect directly to your EC2 instance.
-
Connect to the instance:
- Go to the EC2 dashboard and select the Minecraft server instance.
-
Click Connect at the top.
In the connection screen, make sure the user is set to
ec2-user
, then click Connect again.-
If the connection fails, try rebooting the instance and waiting a few minutes, or review the common troubleshooting tips.
-
Navigate to the server directory:
-
After logging in, you’ll be in a terminal.
Run:
cd /opt/minecraft/server/
. This directory contains all the Minecraft server files. Remember this location for future edits.To check the server files, use the following command:
ls
. You should see files like world/, logs/, server.jar, as well as the start and stop scripts.
-
-
Stop the server before making changes:
- The server console runs in the background, so files can’t be edited while it’s active.
- To stop the server, run:
sudo systemctl stop minecraft
. - Once the service is stopped, you can upload a new world, add plugins or edit configuration files.
-
Restart the server:
- After making changes, restart the instance or run:
sudo systemctl start minecraft
.
- After making changes, restart the instance or run:
💡 Useful commands:
# Start the server sudo systemctl start minecraft # Stop the server sudo systemctl stop minecraft # Restart the server sudo systemctl restart minecraft # Check if the server is running sudo systemctl status minecraft
Clean Up (Avoid Extra Charges)
When you’re done testing or hosting your server, it’s important to shut down resources to prevent ongoing AWS charges.
-
Terminate the EC2 instance:
- In the EC2 dashboard, select your Minecraft instance.
- Click Instance state → Terminate instance.
- Confirm the termination.
-
Release the Elastic IP:
- In the EC2 dashboard, open the sidebar and go to Elastic IPs.
- Select the Elastic IP you associated with your instance.
- Click Actions → Release Elastic IP addresses.
Once done, you will no longer incur charges from this setup.
Resources & Useful Links
- https://medium.com/@pzawadz/how-to-set-up-minecraft-server-java-edition-for-free-for-12-months-on-aws-38239753cca1
- https://aws.amazon.com/blogs/gametech/setting-up-a-minecraft-java-server-on-amazon-ec2/
- https://aws.amazon.com/free/
- https://minecraft.fandom.com/wiki/Tutorials/Setting_up_a_server
This content originally appeared on DEV Community and was authored by carmen

carmen | Sciencx (2025-08-26T22:06:50+00:00) Setting Up Minecraft Server in AWS. Retrieved from https://www.scien.cx/2025/08/26/setting-up-minecraft-server-in-aws/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.