Skip to content

Very cool Minecraft server infrastructure setup for AWS. Created for fun and to practice some skills.

Notifications You must be signed in to change notification settings

lariskovski/minecraft-aws

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minecraft Server for AWS

drawing

Very cool Minecraft server infrastructure setup for AWS. Created for fun and to practice some skills. Making use of EC2, EFS, S3, Route 53, IAM and other AWS services. Terraform and Packer tools (also Cloudflare).

Getting Started

Dependencies

Github Actions Secrets

The following secrets need to be set so the workflows work as expected.

Secret Example Description
AWS_ACCESS_KEY_ID AKIAIOSFODNN7EXAMPLE Setting Up Credentials
AWS_SECRET_ACCESS_KEY wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Setting Up Credentials
TF_VAR_BACKEND_S3_BUCKET my-unique-bucket Bucket name for storing TFstate
CLOUDFLARE_TOKEN uyvUrefBhbuQNsjZJUBZsuBypdnbZVghgEXAMPLE Cloudflare API token
ZONE_ID rnc95m5rsvsvw8z9mm7xx282gEXAMPLE Cloudflare Zone ID where the record is being updated/created.Get the Zone ID
RECORD minecraft.mydomain.com Record being updated to the EC2 instance's Public IP

Executing Locally

  • Export AWS credentials and bucket for tfstate:
export AWS_ACCESS_KEY_ID=XXXXXXXXXXXXXXXXXX
export AWS_SECRET_ACCESS_KEY=ZZZZZZZZZZZZZZZZZZZZZZZZ
export TF_VAR_backend_s3_bucket="tfstates-bucket"
  • Edit env.sh accordingly

  • Deploy data resources: make data-plan and make data-apply

  • Build the image: make packer-build

  • Deploy compute resources: make compute-plan and make compute-apply

  • Optionally edit the cloudflare-update.sh file environments. The script is used in a target to automatically update a Cloudflare dns record with the new EC2's public IP. make cloudflare-update

Packer, Terraform and Cloudflare

What does Packer do?

Packer creates a base image for our server on top of Amazon Linux AMI 2. It setups up anything not data-related.

  • Run packer init on the firest setup or if there are changes to packer-setup-script.sh

  • Format and validate the Packer template packer fmt . and packer validate .

  • Build the image packer build .

What about Terraform?

Creates the infra including:

  • Networking: SG with port 22 and 25565 + make sure to use the default sec group to EFS can access the EC2

  • Data: EFS to hold data across EC2 instances + EFS DNS entry on Route 53

  • Compute: EC2 using Packer base image

Cloudflare

Optionally update Cloudflare DNS entry with new instance's public IP exporting the env vars bellow then running make cloudflare-update

export CLOUDFLARE_TOKEN=xxxxxxxxxxxxxxxxxx
export ZONE_ID=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
export RECORD=minecraft.yourdomain.com

Destroy Monitor

Python script checks via rcon for online players. If its 0 for more than 20 minutes, script calls Github API to trigger the destroy workflow.

Repository dispatch documentation

Create a personal Github token

Make sure you add repo and workflow permissions

Resources

New minecraft releases

Github and Makefiles

Manually Run Github Action

Github Doc