Cost Effectively Hosting Your Favorite Steam Game Server in the Cloud with AWS

Spread the love

So, you want to host your favorite steam game server in a cost-effective way? Hosting it on Amazon Web Services (AWS) is a viable option for you at an affordable price.

Launching an EC2 Instance on AWS

To host a steam game server on AWS. The first thing you need to do is launch an EC2 instance, which can be done in the following steps:

  1. Log into your AWS Account at https://aws.amazon.com
  2. Search for Elastic Compute Cloud (EC2), and click the EC2 link in the results so that you can get to the EC2 dashboard. EC2 is AWS’s Infrastructure as a Service (IaaS).
Searching for EC2

3. Click the launch instance button.

Click launch instance button

4. In the Name field, enter the name of the instance. I’m entering “Garry’s Mod Server”. Select Debian as the operating system for the Amazon Machine Image (AMI).

Enter Instance Name and select AMI

5. For this demonstration, a t2.micro instance type is selected, but I will be discussing how to strategically determine the instance type that works best for you.

Select Instance Type

6. Create a key pair with the name “Garry’s Mod Key Pair”, which you will use to SSH into your EC2 instance. Once you click the Create key pair button, a “Garry’s Mod Key Pair.pem” file will be downloaded to your Downloads folder. This is the file you need to use with SSH, so don’t lose it.

Create a Key Pair

7. Leave all the Network Settings in their default state.

Default Network Settings

8. Set the Configure Storage settings to at least 16 GiB for the Root Volume.

Configure Storage

9. Leave Advanced details to default settings.

10. Click the “Launch Instance” button in the bottom right corner.

11. Lastly, Click the instances link in the EC2 dashboard to ensure that your new EC2 instance is running. (Note: It may take a minute or two, but once it is running you will see that the instance state is Running.)

Instance is Running

Setting up the Steam Game Server on the EC2 Instance

To run the steam game server, you can use the Linux Game Server Managers (https://linuxgsm.com). To illustrate, the following demonstrates how to use LinuxGSM to set up a game server for Garry’s Mod:

  1. Get the Public IPv4 address of your running EC2 instance by selecting your Running EC2 instance, and selecting the Networking tab.

2. SSH into your EC2 instance by using the “Garry’s Mod Key Pair.pem” and using the admin username:

> ssh -i "Garry's Mod Key Pair.pem" [email protected]

3. Ensure that curl and unzip are installed on the system:

> sudo apt install curl unzip
Ensure curl and unzip are installed

4. Install the Fast Node Manager (fnm)

> curl -fsSL https://fnm.vercel.app/install | bash
Install fnm

5. Install the latest Node version:

> fnm i 23.5.0
Install node version 23.5.0

6. Instruct fnm to use the latest Node version:

> fnm use 23.5.0
Use node version 23.5.0

7. Globally install gamedig using the Node Package Manager (npm). (Note: This tool is used by LinuxGSM.)

> npm install gamedig -g
Globally install gamedig

8. Create a Linux user gmodserver for the server to run as:

> sudo adduser gmodserver
Add a user called gmodserver

9. Login to the gmodserver account:

> sudo su - gmodserver
Login as the gmodserver user

10. Install the LinuxGSM and Garry’s Mod Server Manager

> curl -Lo linuxgsm.sh https://linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh gmodserver
Install linuxgsm.sh script and set script as executable

11. Finally, install the Garry’s Mod Server:

> ./gmodserver install
Install Garry’s Mod Server

This can take a few minutes, and it will require you to answer some prompts.

12. Lastly, run the Garry’s Mod Server:

> ./gmodserver start
Start the Garry’s Mod Server

Connecting to the Garry’s Mod Server

Before we can connect to the Garry’s Mod Server with the client, we must enable port 27015, which is the default Garry’s Mod Server port, for the security group of the running EC2 instace. To do so do the following:

  1. Click the Instances link in the EC2 dashboard.
  2. Select the Garry’s Mod Server Instance, and click the Security tab, and click the security group link that starts with “sg-”.
Security Group Link

3. Click the Edit Inbound Rules button of the Security Group:

Edit In Bound Rules of Security Group

4. Click the Add rule button, and set the type to “Custom UDP”, Port range to 27015, and the CIDR to 0.0.0.0/0.

5. Click the Save rules button in the bottom right corner.

Connecting to the Video Game Server

  1. Make sure you have the IPv4 address of your EC2 instance, which you can get from your Network Settings of your running EC2 instance. (If you can’t remember, visit step 1 of the “Setting up the Steam Game Server on the EC2 Instance” section)
  2. Open up the steam game client menu.
  3. Open up the game console by typing ~
  4. Type connect <IPv4 Address of EC2 Instance>:27015 and hit enter
Connecting to the game server through the game console.

5. Finally, you will connect to your game server being hosted in the cloud to play.

Playing on the game server being hosted on the EC2 Instance on AWS.

Creating an Amazon Machine Image of the Steam Game Server (Optional)

You just performed a lot of steps to configure your Steam Game Server, so you might want to take an extra step to ensure you don’t need to do it all over again if you terminate your EC2 instance on purpose or by accident. To create an image of your steam server do the following:

  1. Click the Instances link in the EC2 Dashboard.
  2. Click the “Actions” button in the upper right corner, and select “Image and templates”, and select “Create Image”. (Note: If you notice the “Create Image” option is disabled, then make sure you have your running game server EC2 instance checkbox is selected.
Creating an Image

3. Give the image a name like “Garry’s Mod Server Image”, and then click the “Create Image” button in the bottom right corner. (Note: This will automatically stop the EC2 instance.)

Whenever you want to launch a new EC2 instance with your Game Server already configured and installed, you can select your image under My AMIs.

Selecting your Image when launching a new instance.

Security of Your Game Server

Before letting others join your Game Server, you will want to disable port 22 as an Inbound Rule of the security group so that others won’t have the possibility of gaining unprivileged access to your game server. To do that, edit the Inbound Rules again of the Security Group of the Game Server EC2 instance and remove the SSH rule. When you do that, no one can SSH into the server. If you still want to run commands on the server with SSH disabled you can temporarily reenable SSH so that you can install an AWS Systems Manager (SSM) Agent on your EC2 Instance.

Installing a SSM Agent on your EC2 Instance (Optional)

To run a SSM Agent on the Game Server do the following:

  1. Search for IAM, which is for AWS’s Identity and Access Management service.
  2. Click the Roles link, and then select the “Create Role” button in the upper right corner.
Create Role

3. Set the Trusted entity to AWS service and set the service to EC2, and click the “Next” button in the lower right corner.

Configuring the role

4. Next, search for the role “AmazonSSMFullAccess” permission and select it, and hit the “Next” button in the bottom right corner.

Selecting AmazonSSMFullAccess permission.

5. Give the role a name like “SSM_Access”, and click the “Create role” button in the bottom right corner.

6. Next, go back to the EC2 dashboard and select the “Instances” link. Select your EC2 instance the game server is running on. Select the “Actions” button in the upper right corner. Then, select “Security”, and select “Modify IAM Role”.

Modify the IAM role of the EC2 instance

7. Set the IAM role to “SSM_Access” or whatever you named your IAM role, and click the “Update IAM role” in the bottom right corner.

8. Next, you need to install the amazon-ssm-agent onto the server by connecting to the EC2 instance via SSH and running the following commands:

mkdir /tmp/ssm
cd /tmp/ssm
wget https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/debian_amd64/amazon-ssm-agent.deb
sudo dpkg -i amazon-ssm-agent.deb
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent

9. After successfully running the above commands, you should be able to run the following command to get the status (Note: The amazon-ssm-agent.service must be set to active so that you can connect to the EC2 instance without SSH.)

> sudo systemctl status amazon-ssm-agent
Checking the status of the amazon ssm agent

10. Once you have verified the amazon-ssm-agent is running correctly, you can go back to disabling SSH.

11. Afterwards, Click the “Instances” link in the EC2 dashboard, and stop the EC2 instance by clicking the “Instance state” button in the upper right hand corner and select Stop instance.

12. Once the instance is stopped, set the user data by clicking the “Actions” button in the upper right corner, select the “Instance settings” option, and select the “Edit user data”, and set the user data to the following:

#!/bin/bash
sudo systemctl start amazon-ssm-agent

The above commands will start the amazon-ssm-agent once the EC2 instance starts.

Editing the user data of the EC2 instance

13. Now, start the instance back up, and wait for it to finish initializing.

14. Select the instance, and select the “Connect” button in the upper right corner, and select the Session Manager tab.

Connecting to EC2 instance through the Session Manager instead of SSH.

15. Select the “Connect” button in the bottom right corner.

16. Next, you will see that you are connected to a terminal to your EC2 instance that is not running through SSH for security reasons.

Connected to EC2 through the session manager.

Cost Analysis

AWS provides a lot of flexibility with instance types. This blog post used t2.micro, but you’ll probably want to change that if you want more players on the server. The instance type you choose will vary the cost you pay each month. AWS offers On-Demand prices for EC2 instances and other options, such as 1 or 3 year reserved prices. One caveat is that AWS charges for IPv4 addresses assigned to EC2 instances at a rate of $0.005 per hour (All prices given have this cost included).

A low end server, t3.medium, with 4 GiB of Memory, 2 vCPU, Elastic Block Storage, and 5 Gigabit network performance will cost $34.67 per month for On-Demand prices or $17.11 per month for 3 year reserved no upfront payment.

A mid level server, t3.large, with 8 GiB of Memory, 2 vCPUs, Elastic Block Storage, and 5 Gigabit network performance will cost $65.82 per month for On-Demand prices or $30.43 per month for 3 year reserved no upfront payment.

A high level server, r6i.xlarge, with 32 GiB of Memory, 4 vCPUs, Elastic Block Storage, and 12.5 Gigabit network performance will cost $88.76 per month for 3 year reserved no upfront payment.

If you want to do your own research on pricing, then you can use the following website: Amazon EC2 Instance Comparison.

Also, you can compare these prices to other video game server hosting platforms, such as the following:

Benefits of Using AWS to Host Your Steam Game Server

The Benefits of using AWS are the following:

  • Affordable Pricing
  • DDoS Protection because EC2 instances are protected by AWS Shield
  • Simple Setup
  • Root access to server

As you can see, setting up a steam game server on the cloud is a relatively easy process and much more affordable.

If you found this article helpful, then do the following:

  • Clap for my article 10 times.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *