How would I create a Minecraft EC2 server that automaticaly starts when someone tries to use it

£可爱£侵袭症+ 提交于 2021-02-08 09:50:14

问题


Currently, I have a working modded Minecraft server working running on a C5 EC2 instance. The problem is that I have to manually start and stop the server which can be annoying for my friends. I was wondering if it would be possible to automate the EC2 state so that it runs as soon as a player attempts to join the sever. This would be similar to how Minecraft realms behaves which I heard Mojang was using AWS for: https://aws.amazon.com/blogs/aws/hosting-minecraft-realms-on-aws/

I have looked up tutorials for this and this is the best I could come across: https://github.com/trevor-laher/OnDemandMinecraft

The problem with this solution is that it requires to make a separate website to log users in and start the EC2 instance while I want the startup and shutdown to be completely automatic.

I would appreciate any guidance.


回答1:


If the server is off, it would not be possible to "connect" to the server. Therefore, another mechanism is required that can be used to start the server.

Combine that with your desire to minimise costs and the only real solution is to somehow trigger an AWS Lambda function, which could start the server.

There are a few ways you could have users trigger the AWS Lambda function:

  • Make a call to API Gateway
  • Upload an object to Amazon S3
  • Somehow put a message in an SNS topic or an SQS queue
  • Trigger an Amazon CloudWatch Alarm (which calls Lambda via SNS)
  • ...and probably other ways

When considering a method to use, you should consider security implications such as:

  • Whether only authorized users should be able to trigger the Lambda function, or is it okay that anybody (eg a web crawler) might trigger it.
  • Whether you willing to give your friends AWS credentials (not a good idea) that they could use to start the server directly, or whether it should be an indirect method.

Frankly, I would recommend the following architecture:

  • Create an AWS Lambda function that turns on the server
  • Create an API Gateway that triggers the Lambda function
  • Give a URL to your friends that calls the API Gateway and passes a 'secret' (effectively a password)
  • The API Gateway will call the Lambda function, passing the secret
  • The Lambda function confirms that the secret is correct and starts the Amazon EC2 instance with Minecraft installed

Here is a tutorial that shows many of these concepts: Build an API Gateway API with Lambda Integration

The purpose of the secret is to avoid the server from starting if an unauthorized person (or a bot) happens to hit the API Gateway endpoint. They will not provide the secret, so the server will not be started.

Stopping the server after a period of non-use is a different matter. The library you referenced might be able to assist with finding a way to do this. You could have a script running on the Minecraft server that monitors the game and, after a period of inactivity, simply calls the operating system to perform a Shutdown.




回答2:


You could use a BungeeCord hub server that then allows user to begin a connection to the main server and spin it up via. AWS.

This would require the bungee server to be always up however, but the cost of hosting a small bungee server should be relatively cheap.

I don't think there's any way you could do this without having a small server that receives the initial request to spin up the AWS machine.



来源:https://stackoverflow.com/questions/60806200/how-would-i-create-a-minecraft-ec2-server-that-automaticaly-starts-when-someone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!