mc_on_ec2
v1.0.1
Published
mc_on_ec2 is a promise-based wrapper for the AWS V3 Javascript SDK that makes it easy to manage Minecraft servers.
Downloads
6
Readme
mc_on_ec2
Overview
mc_on_ec2 is a promise-based wrapper for the AWS V3 Javascript SDK that makes it easy to manage Minecraft servers. This module was written in typescript and includes a bash script to configure the Minecraft server and restart it when the instance boots.
Features
API includes functions that allow you to:
A 1.20.4 Minecraft server will be running at all times when the instance is functional and the game state will be preserved across instance restarts.
Usage
To install through NPM, run the following command:
npm i mc_on_ec2
To use this package you must be authenticated with AWS. Follow this link for the latest best practices.
API
Launch
createServer(playerCount: number): Promise<server>
This function will create an EC2 instance running a version 1.20.4 Minecraft server. Networking security policies will be correctly configured and an elastic IP will be created to persist the IP address across instance restarts.
Input
playerCount: a number greater than 1 that indicates the maximum expected player count. This will determine the EC2 instance type to launch as follows:
1 < playerCount < 10 = c6i.large
10 <= playerCount < 20 = c6i.xlarge
20 <= playerCount = c6i.2xlarge
Output
Promise<server>: This promise will conform to the server interface. It will resolve once the server is fully functional. It will be rejected if there are any errors with the AWS call.
Example
import { createServer } from "mc_on_ec2";
createServer(5)
.then((result)=>console.log(result)) // {id: "i-example", ip: "1.1.1.1"}
.catch((error)=> console.log(error)); // May be rejected if the user has not completed AWS authentication procedures.
Stop
stopServer(instanceID: string): Promise<void>
This function will stop the specified server. This will preserve the play-state of the game for all players while minimizing the hosting cost when the server is not in use.
Input
instanceID: A valid EC2 instance ID. Intended to be used in tandem with the output of the createServer function.
Output
Promise<void>: This promise will resolve once AWS has received the stop command. This promise will be rejected if there are any errors with the AWS call.
Example
import { stopServer } from "mc_on_ec2";
stopServer("i-example")
.catch((error)=> console.log(error)); // May be rejected if the user has not followed AWS authentication procedures.
Start
startServer(instanceID: string): Promise<void>
This function will start the specified server. This is intended to be used after the stopServer function in order to resume server functionality.
Input
instanceID: A valid EC2 instance ID. Intended to be used in tandem with the output of the createServer function.
Output
Promise<void>: This promise will resolve once the server is fully functional. This promise will be rejected if there are any errors with the AWS call.
Example
import { startServer } from "mc_on_ec2";
startServer("i-example")
.catch((error)=> console.log(error)); // May be rejected if the user has not followed AWS authentication procedures.
Reboot
rebootServer(instanceID: string): Promise<void>
This function will restart the specified EC2 instance in case of issues with the operating system or Minecraft server.
Input
instanceID: A valid EC2 instance ID. Intended to be used in tandem with the output of the createServer function.
Output
Promise<void>: This promise will resolve once the server is fully functional. This promise will be rejected if there are any errors with the AWS call.
Example
import { rebootServer } from "mc_on_ec2";
rebootServer("i-example")
.catch((error)=> console.log(error)); // May be rejected if the user has not followed AWS authentication procedures.
Terminate
terminateServer(instanceID: string): Promise<void>
This function will terminate the specified EC2 instance and associated elastic IP. Warning: This is not reversible and the game state will be lost. Warning: This will terminate both the instance and the elastic IP. Use carefully when deleting servers not generated using this module.
Input
instanceID: A valid EC2 instance ID. Intended to be used in tandem with the output of the createServer function.
Output
Promise<void>: This promise will resolve once AWS has received the termination command. This promise will be rejected if there are any errors with the AWS call.
Example
import { terminateServer } from "mc_on_ec2";
terminateServer("i-example")
.catch((error)=> console.log(error)); // May be rejected if the user has not followed AWS authentication procedures.
Types
server
interface server {
'id': string,
'ip': string;
}
The id declaration represents the AWS EC2 instance ID. The ip declaration represents the elastic IP associated with the instance.