SkillAgentSearch skills...

GameServerEC2Discord

Run very cheap game servers (Minecraft, LinuxGSM, etc) in AWS EC2 Spot instances controlled by Discord slash commands. Manage using Terraform

Install / Use

/learn @g-otn/GameServerEC2Discord

README

Game Server EC2 Discord

Terraform files to manage cheap EC2 Spot instances to host game servers controlled by Discord chat.

Made for and tested with private small servers with few players.

https://github.com/user-attachments/assets/e2e63d59-3a4e-4aaa-8513-30243aafa6c4

Table of Contents

Supported games

Supported

LinuxGSM

LinuxGSM is a deployment and managment tool for Linux dedicated game servers.

[!WARNING] Not all games supported by LinuxGSM have been tested with this project. See also usage stats.

Others

  • You can run other game servers' Docker containers by using the custom server module option and specifying more technical configurations. See Custom game and custom game example.

Strategy

The idea is reduce costs by mainly:

  1. Start the server only when players want to play, instead of having it running 24/7
  2. Automatically stop the server when there are no players
  3. Avoid paying for a domain/etc by using a DDNS service
  4. Using spot instances

This is achieved by:

  1. Starting the server via Discord slash commands interactions
    • Slash commands work via webhook which don't require a Discord bot running 24/7, so we can use AWS Lambda + Lambda Function URL
  2. Using the Auto-stop feature from itzg/docker-minecraft-server, or watching for active connections in a specific port, alongside a systemd timer
  3. Setting up Duck DNS inside the instance (No-IP could work too)

Workflow

After setup, the process of starting and automatically stopping a game server works as follows:

  1. The player types /start in a Discord server text channel
  2. Discord calls our Lambda function via its Function URL
  3. The Lambda function sends the interaction token alongside the start command to another Lambda via SNS and then ACKs the interaction to try avoiding Discord's 3s interaction response time limit.
  4. The other Lambda which can take its time, in this case, starts the EC2 instance. Other commands such as stop, restart, ip and status can stop, reboot and describe the instance.
  5. The instance starts
  6. The DDNS systemd service updates the domain with the new IP
  7. The game systemd service runs the Docker Compose file to start the server
  8. The instance shutdown systemd timer starts checking if the container is running
  9. After a minute or so (depending on the game, instance, etc), the server is ready to connect and play
  10. After 10 minutes without a connection or after the last player disconnects, the server is shutdown automatically via the Auto-stop feature (Minecraft) or a systemd service (other games).
  11. After a minute or so, the instance shutdown systemd timer/service notices that the container is stopped and shuts down the whole instance.

Diagram

Minecraft: diagram

<details> <summary>Other games</summary>

diagram others

</details>

Cost breakdown

TL;DR

Assuming one server and AWS free tier/offers:

  • Minecraft: ~0.7 USD for 30h of gameplay using 1x 2.7GHz vCPU and 8GiB DDR5 RAM (estimate)
  • Terraria: ~0.5 USD for 30h of gameplay using 1x 3.7 GHz vCPU and 4GiB of DDR5 RAM (estimate)
  • Factorio: ~0.7 USD for 30h of gameplay using 1x 3.7 GHz vCPU and 4GiB of DDR5 RAM (estimate)
  • Satisfactory: ~0.9 USD for 30h of gameplay using 1x 3.7 GHz vCPU and 8GiB of DDR5 RAM (estimate)
  • Valheim: ~1 USD for 30h of gameplay using 2x 3.2 GHz vCPU and 4GiB of DDR5 RAM (estimate)
  • Palworld: ~2.5 USD for 30h of gameplay using 4x 3.2 GHz vCPU and 8GiB of DD5 RAM (estimate)

AWS Pricing Calculator estimates do not include Public IP cost, see tables below.

Notable expenses

Again, these are just estimates and EC2 pricing varies with time due to a number of factors.

  • ☑️ - Covered by 12-month Free Tier (assuming one server)
  • ✅ - Covered by monthly Always Free offers (assuming one server)
<details open> <summary><b>Minecraft</b></summary>

| 12FT | AF | Service | Sub-service / description | Price/hour | Price 30h/mo | Price 30h/mo w/ free tier/offers | Price 0h/mo (not in use, no free tier/offers) | | ---- | --- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | ------------ | -------------------------------- | --------------------------------------------- | | | | EC2 | r8g.medium spot instance | $0.022 | $0.66 | $0.66 | | | ☑️ | | EBS | 4GB root volume + 5GB game data volume | - | $0.72 | - | $0.72 | | | | EBS | (Optional) Snapshots of 5GB game data volume | - | ~$0.25 | | ~$0.25 | | ☑️ | | VPC | Public IPv4 address | $0.005 | $0.15 | - | | | | ✅ | VPC | ~10GB of outbound network data (example) | $0.003 | $0.9 | - | | | | | | Total

View on GitHub
GitHub Stars13
CategoryDevelopment
Updated7mo ago
Forks2

Languages

HCL

Security Score

87/100

Audited on Aug 6, 2025

No findings