Skip to content

Commit 43f9821

Browse files
authored
1.2.2 Update (#57)
- Add support to specify backup directories - Fixes incorrect lambda packing - Add MineCloud Configuration Package support
1 parent 4bd7017 commit 43f9821

34 files changed

+296
-24
lines changed

lambda/discord_interactions_endpoint/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Context } from 'aws-lambda';
22
import { sign } from 'tweetnacl';
33
import { Lambda } from 'aws-sdk';
4-
import { STACK_PREFIX } from '../../lib/mine-cloud-stack';
54

65
exports.handler = async (event: any, context: Context) => {
76
const PUBLIC_KEY = process.env.PUBLIC_KEY!;
@@ -37,7 +36,7 @@ exports.handler = async (event: any, context: Context) => {
3736
const lambda = new Lambda();
3837
const res = await lambda
3938
.invokeAsync({
40-
FunctionName: `${STACK_PREFIX}_discord_command_processor_lambda`,
39+
FunctionName: process.env.DISCORD_COMMAND_PROCESSOR_FUNCTION_NAME!,
4140
InvokeArgs: JSON.stringify(event)
4241
})
4342
.promise();

lib/discord-interactions-endpoint-construct.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import path = require('path');
99
import { PolicyStatement, Policy } from 'aws-cdk-lib/aws-iam';
1010
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
1111
import { Duration } from 'aws-cdk-lib';
12-
import { DISCORD_APP_ID } from '../minecloud_configs/MineCloud-Configs';
1312
import { Bucket } from 'aws-cdk-lib/aws-s3';
1413

1514
export interface DiscordInteractionsEndpointConstructProps {
1615
instanceId: string;
1716
ec2Region: string;
17+
discordAppId: string;
1818
discordPublicKey: string;
1919
backUpBucket: Bucket;
2020
}
@@ -31,44 +31,46 @@ export class DiscordInteractionsEndpointConstruct extends Construct {
3131
) {
3232
super(scope, id);
3333

34-
this.discordInteractionsEndpoint = new NodejsFunction(
34+
this.discordCommandProcesser = new NodejsFunction(
3535
this,
36-
`${STACK_PREFIX}_discord_interactions_endpoint_lambda`,
36+
`${STACK_PREFIX}_discord_command_processor_lambda`,
3737
{
38-
functionName: `${STACK_PREFIX}_discord_interactions_endpoint_lambda`,
38+
functionName: `${STACK_PREFIX}_discord_command_processor_lambda`,
3939
runtime: Runtime.NODEJS_18_X,
4040
handler: 'index.handler',
4141
entry: path.join(
4242
__dirname,
43-
'/../lambda/discord_interactions_endpoint/index.ts'
43+
'/../lambda/discord_command_processer/index.ts'
4444
),
4545
environment: {
46-
PUBLIC_KEY: props.discordPublicKey
46+
INSTANCE_ID: props.instanceId,
47+
EC2_REGION: props.ec2Region,
48+
APP_ID: props.discordAppId,
49+
BACKUP_BUCKET_NAME: props.backUpBucket.bucketName
4750
},
48-
memorySize: 1024 // To reduce cold start time
51+
timeout: Duration.seconds(15)
4952
}
5053
);
5154

52-
this.discordCommandProcesser = new NodejsFunction(
55+
this.discordInteractionsEndpoint = new NodejsFunction(
5356
this,
54-
`${STACK_PREFIX}_discord_command_processor_lambda`,
57+
`${STACK_PREFIX}_discord_interactions_endpoint_lambda`,
5558
{
56-
functionName: `${STACK_PREFIX}_discord_command_processor_lambda`,
59+
functionName: `${STACK_PREFIX}_discord_interactions_endpoint_lambda`,
5760
runtime: Runtime.NODEJS_18_X,
5861
handler: 'index.handler',
5962
entry: path.join(
6063
__dirname,
61-
'/../lambda/discord_command_processer/index.ts'
64+
'/../lambda/discord_interactions_endpoint/index.ts'
6265
),
6366
environment: {
64-
INSTANCE_ID: props.instanceId,
65-
EC2_REGION: props.ec2Region,
66-
APP_ID: DISCORD_APP_ID,
67-
BACKUP_BUCKET_NAME: props.backUpBucket.bucketName
67+
PUBLIC_KEY: props.discordPublicKey,
68+
DISCORD_COMMAND_PROCESSOR_FUNCTION_NAME: this.discordCommandProcesser.functionName
6869
},
69-
timeout: Duration.seconds(15)
70+
memorySize: 1024 // To reduce cold start time
7071
}
7172
);
73+
7274
this.discordCommandProcesser.grantInvoke(this.discordInteractionsEndpoint);
7375
props.backUpBucket.grantReadWrite(this.discordCommandProcesser);
7476

lib/instance-init.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ export function getInitConfig(backupBucketName: string) {
126126
InitCommand.shellCommand('systemctl start minecloud.service')
127127
]),
128128
setupBackupScripts: new InitConfig([
129+
InitFile.fromFileInline(
130+
`${MINECLOUD_BASE_DIR}/backup-folders.txt`,
131+
'minecloud_configs/advanced_configs/backup-folders.txt'
132+
),
133+
// To convert Windows's EOL to Linux
134+
InitCommand.shellCommand(`sed -i 's/\r//' backup-folders.txt`, {
135+
cwd: MINECLOUD_BASE_DIR
136+
}),
129137
...setUpEnviromentVariable('BACKUP_BUCKET_NAME', backupBucketName),
130138
...setUpShellScript(
131139
MINECLOUD_BASE_DIR,

lib/mine-cloud-stack.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class MineCloud extends Stack {
8484
{
8585
instanceId: this.ec2Instance.instanceId,
8686
ec2Region: this.region,
87+
discordAppId: DISCORD_APP_ID,
8788
discordPublicKey: DISCORD_PUBLIC_KEY,
8889
backUpBucket: this.backupBucket
8990
}

minecloud_configs/MineCloud-Configs.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// MineCloud Version: 1.2.2
2+
13
// ---------------- Required -------------------- //
24
export const AWS_ACCOUNT_ID = '';
35
export const AWS_REGION = '';
@@ -8,15 +10,15 @@ export const DISCORD_BOT_TOKEN = '';
810
export const DISCORD_CHANNEL_WEB_HOOK = '';
911

1012
// ------------- CloudFormation ------------- //
11-
export const STACK_NAME = 'Minecraft';
13+
export const STACK_NAME = 'Minecraft';
1214

1315
// -------------- Server Executable ------------- //
1416
// If set to true, /minecloud_configs/server/server.zip will be deployed
15-
export const DEPLOY_LOCAL_SERVER_EXECUTABLE = false;
17+
export const DEPLOY_LOCAL_SERVER_EXECUTABLE = false;
1618

1719
// ----------------EC2 Machine Settings-------------------- //
1820
// EC2 max price per hours, in dollars
19-
export const MAX_PRICE = 0.1;
21+
export const MAX_PRICE = 0.1;
2022
// EC2 instance type, refer to https://aws.amazon.com/ec2/instance-types/ for more info
2123
export const EC2_INSTANCE_TYPE = 't2.large';
2224
// Disk size, in GB

minecloud_configs/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Please download and unzip MineCloud Configuration Package to this folder.
2+
The folders hierarchy should look like this:
3+
```
4+
- /MineCloud_root_folder
5+
- /minecloud_configs
6+
- MineCloud-Configs.ts
7+
- /server
8+
- ...
9+
- /advanced_configs
10+
- ...
11+
- /bin
12+
- /lambda
13+
- /lib
14+
- /server_init_assets
15+
- ...
16+
```
17+
The pairing MineCloud version of the Configuration Package can be found in `MineCloud-Configs.ts`.
18+
19+
An out-of-the-box Minecraft server example, `minecraft_example_config_pack.zip`, can also be found in this folder.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/opt/minecloud/server
4.42 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MineCloud: Minecraft Configuration Package
2+
3+
// To-do
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// MineCloud Version: 1.2.2
2+
3+
// ---------------- Required -------------------- //
4+
export const AWS_ACCOUNT_ID = '';
5+
export const AWS_REGION = '';
6+
7+
export const DISCORD_APP_ID = '';
8+
export const DISCORD_PUBLIC_KEY = '';
9+
export const DISCORD_BOT_TOKEN = '';
10+
export const DISCORD_CHANNEL_WEB_HOOK = '';
11+
12+
// ------------- CloudFormation ------------- //
13+
export const STACK_NAME = 'Minecraft';
14+
15+
// -------------- Server Executable ------------- //
16+
// If set to true, /minecloud_configs/server/server.zip will be deployed
17+
export const DEPLOY_LOCAL_SERVER_EXECUTABLE = false;
18+
19+
// ----------------EC2 Machine Settings-------------------- //
20+
// EC2 max price per hours, in dollars
21+
export const MAX_PRICE = 0.1;
22+
// EC2 instance type, refer to https://aws.amazon.com/ec2/instance-types/ for more info
23+
export const EC2_INSTANCE_TYPE = 't2.large';
24+
// Disk size, in GB
25+
export const EC2_VOLUME = 16;
26+
// Init time out, in minutes
27+
export const EC2_INIT_TIMEOUT = 15;
28+
29+
// --------------- Backup Settings------------------ //
30+
// At most how many backups
31+
export const MAX_BACKUP_COUNT = 3;
32+
export const BACKUP_INTERVAL_IN_SECONDS = 10800;

0 commit comments

Comments
 (0)