On-Demand Minecraft Server running on ECS(Fargate) and deployed via CDK (Go)
APACHE-2.0 License
This CDK app sets up a quick, low-cost way to play Minecraft with friends without needing a 24/7 server The server automatically starts when players connect and stops when idle, helping reduce costs by running only when needed.
The idea was to spin up the server only when needed and save on costs by shutting it down when idle. Along the way, it was a chance to learn about using ECS for container management and EFS for persistent storage. π
java
or bedrock
- Specify the Minecraft edition.8192
).4096
).10
).20
).false
).true
).LATEST
)Welcome to the server
)easy
)20
)true
)true
)true
)false
)true
)256
)true
)true
)true
)survival
)true
)true
)false
)1
)minecraft:default
)0
to disable)10
)false
)false
)MinecraftServerStack
).env_example
to .env
and configure before deployment.Requires Go
(1.23+) + cdk
(2.16+). You'll also need an AWS Account. Furthermore a Route 53 domain and a Hosted Zone ID is required for this deployment to work.
Clone the Repository
git clone https://github.com/cbrgm/cdk-on-demand-minecraft-server.git
cd cdk-on-demand-minecraft-server
Configure Environment Variables
.env_example
to .env
:
mv .env_example .env
.env
to set the required and optional environment variables.Deploy the CDK Stack
make sync
make cdk-deploy
flowchart TD
subgraph us-east-1 [AWS Region: us-east-1]
Route53[Route 53 DNS]
CloudWatchLogs1[CloudWatch DNS Logs]
LogForwarder[Log Forwarder Lambda]
Route53 -->|DNS Query: SERVER_SUBDOMAIN.DOMAIN| CloudWatchLogs1
CloudWatchLogs1 -->|Log Entry Trigger| LogForwarder
end
subgraph custom-region [AWS Region: custom-region user-defined]
subgraph VPC [VPC]
ECSService[ECS Service]
MinecraftServer[Minecraft Server Container]
Watchdog[Watchdog Container]
EFS[EFS Volume]
MinecraftServer -- Persistent Game Data --> EFS
ECSService -->|Deploys| Watchdog
ECSService -->|Deploys| MinecraftServer
end
LogForwarder -->|Forward Logs| CloudWatchLogs2
CloudWatchLogs2[CloudWatch Forwarded Logs]
LambdaFunction[AWS Lambda Function]
SNS[Amazon SNS]
User[User]
CloudWatchLogs2 -->|Log Entry Trigger| LambdaFunction
LambdaFunction -->|Set desired-count: 1| ECSService
Watchdog -->|Monitors Server Activity| ECSService
Watchdog -->|Send Status Notification| SNS
SNS -->|Email Status| User
Route53 -.->|DNS Request| User
end
SERVER_SUBDOMAIN.DOMAIN
, Route 53 directs the DNS query, initiating the process.us-east-1
log group to a log group in a user-defined region.desired-count
of the ECS Service to 1, starting the Minecraft server and watchdog containers.Disclaimer: The pricing heavily depends on usage patterns. There are certainly cheaper options for running a Minecraft server, but this setup is serverless, offering flexibility and scalability, which comes at a cost.
Component | Pricing Details | Calculation | Estimate (USD) |
---|---|---|---|
ECS Fargate | $0.04048/vCPU-hour, $0.004445/GB-hour | vCPU: 4 Γ $0.04048 = $0.16192/hour | |
RAM: 8 Γ $0.004445 = $0.03556/hour | |||
Total per hour: $0.19748 | |||
Monthly (24 hours): 24 Γ $0.19748 | $4.74 | ||
AWS Lambda | Free Tier covers 10,000 invocations | No additional cost | $0.00 |
CloudWatch | Free Tier (5 GB logs/month) | No additional cost | $0.00 |
EFS | $0.30/GB-month | 10 GB Γ $0.30 | $3.00 |
Route 53 | $0.50/hosted zone, $0.40/million queries | 1 hosted zone: $0.50 | |
Queries: 10,000 β $0.01 | |||
Total: $0.50 + $0.01 | $0.51 | ||
SNS | Free Tier (1,000 notifications) | No additional cost | $0.00 |
Total | $8.25 |
My development time invested in this project comes for free π
us-east-1
?us-east-1
. Whoever decided that...Special Thanks to the following projects:
We welcome and value your contributions to this project! π If you're interested in making improvements or adding features, please refer to our Contributing Guide. This guide provides comprehensive instructions on how to submit changes, set up your development environment, and more.
Please note that this project is developed in my spare time and is available for free ππ». As an open-source initiative, it is governed by the Apache 2.0 License. This license outlines your rights and obligations when using, modifying, and distributing this software.
Your involvement, whether it's through code contributions, suggestions, or feedback, is crucial for the ongoing improvement and success of this project. Together, we can ensure it remains a useful and well-maintained resource for everyone π.