Package: awscdk-minecraft
awscdk-minecraft🧱The goal of this project is to make a single pip-installable package that allows anyone
to provision an entire,cheap, Minecraft-server-hosting Platform as a Service to their
personal Amazon Web Services account.LoginStart a serverGet the IP addressConnectPlay!Usage(1) Be sure to have the the following installed:Python3.8 or higherNodeJS14 or higher (a dependency of the AWS CDK CLI)AWS CDK CLIDocker(should be installed andrunning)Note: This library makes use of some of AWS's public docker images.You will need to log intoAWS's public docker registry (public.ecr.aws).# get a temporary login session to public.ecr.awsawsecr-publicget-login-password--regionus-east-1|dockerlogin--usernameAWS--password-stdinpublic.ecr.aws(2) Install the AWS CDK stack exposed by this packagepipinstallawscdk-minecraft(3) Use it in your CDK app# app.pyimportosfromaws_cdkimportApp,Environmentfromcdk_minecraftimportMinecraftPaasStackAPP=App()MinecraftPaasStack(APP,"awscdk-minecraft",# login_page_domain_name_prefix just needs to be unique across all AWS accountslogin_page_domain_name_prefix="mlops-club-minecraft-login")APP.synth()Note:app.pyis an AWS Cloud Development Kit concept. If you are not familiar with
AWS CDK and what anapp.pyfile is, you can read more about it in theAWS CDK docs.(4) Create a Cognito User in the AWS ConsoleYou will need to register a user in AWS Cognito UI so that you can log into the website
deployed by the stack. A Cognito User Pool is created by the stack for this purpose. You
can create a user in that user pool. It will be in whichever region you deployed the stack to.(5) Play!One of the stack outputs will be the URL of the Minecraft Platform frontend. Visit the
site, log in, and start your server!Share this link with friends and create Cognito users for them as well if you
want them to be able to start and stop the server, too.Otherwise, just share the IP address with any friends you'd like to be able to join the game.Advanced Usage📌Note:For a complete, working example of the advanced usage, you can refer tothis other repository.Pretty domain nameYou can add the components of your minecraft stack as subdomains of a custom
domain name.You will need to have a domain name registered with AWS Route53.For example, for the domainmlops-club.orgyou can create these mappings:minecraft-paas.mlops-club.org-> the PaaS UI to start/stop the serverserver.minecraft-paas.mlops-club.org-> the minecraft server, whenever the EC2 instance is running# app.pyimportosfromaws_cdkimportApp,Environmentfromcdk_minecraftimportMinecraftPaasStackAPP=App()MinecraftPaasStack(APP,"awscdk-minecraft",# login_page_domain_name_prefix just needs to be unique across all AWS accountslogin_page_domain_name_prefix="mlops-club-minecraft-login")APP.synth()Connecting to the server over SSHAfter starting a temporary EC2 instance with the minecraft server, you can
connect to it over SSH if you set up a keypair.Create a keypair, for example, using an existing SSH keypair.# create a new keypair from ~/.ssh/id_rsa.pubSSH_KEY_PAIR_NAME=eric-key
awsec2import-key-pair--key-name$SSH_KEY_PAIR_NAME--public-key-materialfile://~/.ssh/id_rsa.pub--profile<your-aws-profile>--region<your-minecraft-aws-region>If you have trouble with this command, you can always create the key pair in the AWS Console.Register the keypair with your stack.# app.py...MinecraftPaasStack(APP,"awscdk-minecraft",...ssh_key_pair_name="my-keypair",)...Connect to the instance when the server is running.ssh-i~/.ssh/id_rsaec2-user@<instance-ip-address>Customizing the server and running commands as adminThe Minecraft server runs on the EC2 instance usingdocker-compose.The container is calleditzg/docker-minecraft-server. Specifically, using an
optimized Minecraft server JAR calledPaper.Paper is
a fork of the popularSpigotserver, which in turn
is a fork of CraftBukkit. Spigot and Bukkit "plugins" (mods) likeWorldEditare supported by Paper.The file structure of the server is like this:/minecraft
├── docker-compose.yml
└── minecraft-data/     # mounted volume
    ├── ...
    └── server.propertiesTo issue commands on the server:# connect to the instancessh-i~/.ssh/id_rsaec2-user@<instance-ip-address># operate as root to have docker privilegessudosu# start an RCON sessiondockerexec-iminecraftrcon-cliMuchmore detailed documentation for operating the minecraft server
can be found in theitzg/docker-minecraft-serverdocs:Image taken fromitzg/docker-minecraft-serverContributingThis project started as a December 2022 month-long Hackathon.Contributors can expect to come away with an enviable amount of real-world cloud architecture
experience :DArchitectureThe project has 5 components:awscdk-minecraft/the Python package. Uses AWS CDK to create the infrastructure.
The other folders in this repository are artifacts that this package includes (and deploys!).minecraft-platform-frontend/a React/TypeScript website where users can start/stop a Minecraft server.
Theawscdk-minecraftpackage deploys this as a static website in an S3 bucket.minecraft-platform-backend-api/a REST API written with the FastAPI framework that facilitates
the functionality exposed in the frontend. Theawscdk-minecraftpackage deploys this API
as in a serverless way using AWS Lambda, API Gateway, and Cognito.minecraft-platform-backup-servicea sidecar container that runs alongside theitzg/minecraft-servercontainer
(the Minecraft server) on the EC2 instance. It backs up the save files every N minutes, and restores from
the most recent backup when the EC2 starts up.awscdk-minecraft-server-deployer/another AWS CDK package. This package is specifically responsible
for creating and destroying an EC2 instance with the Minecraft server application running on it.
This package itself is built into a Docker image. Theawscdk-minecraftpackage
builds the Docker image with this package inside. Then, when users ask theminecraft-platform-backend-apito create or destroy a Minecraft server. The REST API runs an instance of this Docker image
which actually carries out the request.The setup has only been tested for Linux and MacOS, not Windows :(.
If you're on windows, you'll have the best contributor experience using the Windows Subsystem for Linux 2 (WSL2).Useful links💡 Click the images to go to each collaboration tool.💡 Bookmark this repository so you can get quick access to these links.Our virtual park (for remote collab)Slack, in the#hackathonchannelRoadmap, tasksArchitecturemlops-clubAWS account login pageSimilar project with reference code / resourcesHow do I run this project locally?TL;DR, installnodeandjust.# install "just"; it's like "make", but less frustrating
brew install just

# install the project's python packages and pre-commit
just installAlternatively, withoutbrew:curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to <DEST IN YOUR PATH>whereDEST IN YOUR PATHrefers to a directory that is present in your$PATHenvironment variable. For example, you might have in your~/.bashrcthe linePATH=~/bin:$PATHto look for programs in~/binfirst, which would be the "DEST" supplied above.You also neednodeto execute any code related to AWS CDK, which you can install withbrew install nvmandnvm install 18.How do I add code?Branching strategy: trunk-based development with feature branchesWe use pull requests. Create new branches based ontrunkfor experimentation, then open a PR for it.
You don't have to wait until you want to merge code to open a PR. For this project, the main purpose of doing PRs
is to share knowledge and get early feedback on your ideas.LintingPassing thepre-commitchecks isn't a huge deal. They are mostly for your own benefit to prevent you
committing things to the repo that you don't want. You can always overridepre-commitby running# run all of the quality checking tools against your codejustlint# skip the quality checking tools locallygitcommit-m"I really want to commit this large file"--no-verifyGit configuration📌 Note: you may want to use a different email/username for this repository than
you typically use on your development machine. You can set your git settings locally
like so:gitconfig--localuser.emailmy-personal-email@gmail.com
gitconfig--localuser.usermy-github-usernameNotes on commitsDON'T COMMIT...credentials. Feel free to put them in a.envfile, but make sure it's gitignored!large files (large CSV, ML model weights, C binaries, video, etc.)
use git LFS rather than committing it directly.unformatted codeThe pre-commit hooks setup for this repo when you ranjust installwill remind you
about these each time you commit :)FeaturesCustom URL for siteCustom URL for minecraft serverSpecify existing SSH key pair to look upSpecify server version