Godot Multiplayer Networking: Hosting a dedicated server on AWS EC2

This guide will cover:

What this guide does not cover:

Pre-requisites:

AWS Steps 📷

(All images are at the bottom. Click the 📷 in each section title to see them.)

In this section we will make:

** Note: See footnotes about my instance choice & costs





Terminal Steps 📷

The next section uses commands that should have their values replaced.

Here are the commands. Copy them to a text editor & replace each of the values, IPs, Godot versions with your choices as you go & save it. In the future I may make a tool to speed this up, but this works for now.

chmod 400 godot_example.pem

ssh -i "godot_example.pem" ec2-user@3.224.219.2

sudo yum install wget && sudo yum install unzip && wget https://github.com/godotengine/godot-builds/releases/download/4.5-dev5/Godot_v4.5-dev5_linux.arm64.zip && unzip Godot_v4.5-dev5_linux.arm64.zip

scp -i godot_example.pem tundra_server.arm64 ec2-user@3.224.219.2:/home/ec2-user/

./Godot_v4.5-dev5_linux.arm64 --main-pack tundra_server.arm64 --headless  -- server
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for 'mykey.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
...
sudo yum install wget && sudo yum install unzip && wget https://github.com/godotengine/godot-builds/releases/download/4.5-dev5/Godot_v4.5-dev5_linux.arm64.zip && unzip Godot_v4.5-dev5_linux.arm64.zip

Godot Exporting Steps 📷

func _ready():
    if OS.has_feature('server'):
		print("Calling host game for dedicated server setup...")
        # Note: your host command may be different, but it should start the host locally when called.
        ... 
        ...
        host()

Upload and run your server 📷

Final step:

This is what it looks like when I join my game, Tundra (I prefill the Elastic IP in my game for easy testing for now):

alt text


Here are all the steps as images, in order. I may make a video or carousel, but this works for now. If you copy the commands from above and follow these visuals, you'll get there.

AWS: Create security group, EC2 instance, and Elastic IP

alt text alt text alt text alt text alt text alt text alt text alt text


Commands in your terminal

alt text alt text alt text alt text


Export from Godot to Linux as a dedicated server

alt text alt text alt text


Upload to the EC2 with scp and run in the background on the EC2 using screen

alt text alt text alt text alt text


Footnotes:

** The AWS steps could apply to other cloud host providers like Digital Ocean or GCP (my costs are currently $3.00 per month on AWS). Note on our choice of t4g.nano: I chose the smallest 64-bit (Arm) architecture because it can save on costs with the CPU usage we expect. ARM is just slightly more efficient. You can use an x86 architecture, like a t2.micro, but you'll need to change many of the commands and carefully look at the Export options in Godot. x86 is the default export in Godot for Linux.

You can use the network profiler to estimate how much bandwidth you'll need. Some of the slightly larger instances come with better network throughput, though my game takes about 25 kB/s for each connected client, averaging about 100 KB/s on the server with 4 people connected. By my calculations I'm unlikley to run up against the limits, but I'll update this when I move to a more robust architecture. This set up is designed to be applicable to a variety of use cases, like a home server. Another cool note: I was able to use ssh and scp to export it to & then run a client on my Steam Deck!