= How can I automate my AWS EC2 Minecraft server so that it is only running when people are online? =

![ ](httpswww.redditstatic.com/desktop2x/img/renderTimingPixel.png)

I want the server to be offline when no one is one and online when someone try’s to connect.

Yes this one! There's a working CDK implementation now too.

I've got a work in progress branch for live editing of server files with cloudshell and ECS exec so you don't have to set up complex tasks for it. Just needs a little more testing

how about getting it to trigger off of a firewall log of a user connecting to the Minecraft tcpip port?

Discord bot to fire a webhook to a lambda to turn on//off the instance is something ppl do

Here's just an example I'm not saying this is what you want exactly but this is the basic premise:

httpsdrpump.github.io/ec2-discord-bot/

Might be of interest httpssidoine.org/how-to-run-a-minecraft-server-on-aws-for-less-than-3-usd-a-month

I

In broad strokes:

Write a python script that starts your EC2 instance.

Run the script from a lambda function.

Create a URL that invokes the lambda.

Automate shutting down the EC2 instance when idle.

Warning: There are lots of ways to do these things wrong and have someone take over your account and run up a huge bill.

This would be an accepted way to orchestrate an EC2 instance. Scope down a service acct with a minimal role tied just to that shutdown instance.

You can grant them IAM access to only start/stop an instance. Alternatively, you can expose this via lambda http integration and have it as a webhook that starts instance (think about security aspects of this). For shutting down, you could automate this aspect using VPC flow logs and if there's no traffic to the Minecraft server port in last N minutes,it down?

httpsgithub.com/infinisil/on-demand-minecraft is a pretty cool trick, but I'm not sure where he's running the forwarding proxy.

You have a chicken and egg problem. It has to already be running for a user to be able to try to connect to it in the first place.

You could make a little launcher web app that can send a command to start the server if it's off. If all of your friends know to check that first and wait a few minutes (or whatever the startup time is) before an SMS message is sent to them confirming that it's running then this could work.

It's not super streamlined but it's a solution.

Gotcha. Is there a way I can have my friends launch an instance and close it when they are done?


You could have them hit a lambda endpoint that starts the instance then configure it to shutdown if no connections after X time inside the instance via a simple cron job.

httpsbriancaffey.github.io/2021/03/18/on-demand-dedicated-serverless-valheim-server-with-cdk-discrod-interactions/

This, except instead of a Valheim CDK container, use paper.

I made a simple web UI for powering on/off an EC2 instance. It uses API Gateway to serve the page and control the instance so essentially free.

httpsgithub.com/davidcomerford/sketchy-router-controller

I use it to turn on/off my VPN instance if anyone is wondering about the name.