Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nodejs12 end of support on lambda + Improvement to the minecraft cloudwatch filter + 50% reducement in AWS cost #61

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ You may be asked to install a package like aws-cdk, this is fine to say yes to.

### 5. Customize your server

After deploying go to the hosted zone you firstly created for your domain and click on `View query logging configuration` and select the `/aws/route53/{subdomain.domain}` log group.

### 6. Customize your server

After you've launched your minecraft server the first time and you've waited for it to finishing generating the world with all defaults, you'll need to get in, make yourself an op, tweak settings, etc. There are several ways to do this, many of which are outlined at [Usage and Customization] on the main page.

## Additional Configuration
Expand Down
2 changes: 1 addition & 1 deletion cdk/lib/cw-global-resource-policy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { custom_resources as cr, aws_iam as iam, Duration } from 'aws-cdk-lib';
import { RetentionDays } from 'aws-cdk-lib/lib/aws-logs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { Construct } from 'constructs';

interface CWGlobalResourcePolicyProps {
Expand Down
36 changes: 13 additions & 23 deletions cdk/lib/domain-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Construct } from 'constructs';
import { constants } from './constants';
import { CWGlobalResourcePolicy } from './cw-global-resource-policy';
import { RetentionDays } from 'aws-cdk-lib/lib/aws-logs';
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
import { StackConfig } from './types';

interface DomainStackProps extends StackProps {
Expand Down Expand Up @@ -68,25 +68,8 @@ export class DomainStack extends Stack {
domainName: config.domainName,
});

const subdomainHostedZone = new route53.HostedZone(
this,
'SubdomainHostedZone',
{
zoneName: subdomain,
queryLogsLogGroupArn: queryLogGroup.logGroupArn,
}
);

/* Resource policy for CloudWatch Logs is needed before the zone can be created */
subdomainHostedZone.node.addDependency(cloudwatchLogResourcePolicy);
/* Ensure we hvae an existing hosted zone before creating our delegated zone */
subdomainHostedZone.node.addDependency(rootHostedZone);

const nsRecord = new route53.NsRecord(this, 'NSRecord', {
zone: rootHostedZone,
values: subdomainHostedZone.hostedZoneNameServers as string[],
recordName: subdomain,
});
rootHostedZone.node.addDependency(cloudwatchLogResourcePolicy);

const aRecord = new route53.ARecord(this, 'ARecord', {
target: {
Expand All @@ -103,11 +86,11 @@ export class DomainStack extends Stack {
*/
ttl: Duration.seconds(30),
recordName: subdomain,
zone: subdomainHostedZone,
zone: rootHostedZone,
});

/* Set dependency on A record to ensure it is removed first on deletion */
aRecord.node.addDependency(subdomainHostedZone);
aRecord.node.addDependency(rootHostedZone);

const launcherLambda = new lambda.Function(this, 'LauncherLambda', {
code: lambda.Code.fromAsset(path.resolve(__dirname, '../../lambda')),
Expand Down Expand Up @@ -137,10 +120,17 @@ export class DomainStack extends Stack {
/**
* Create our log subscription filter to catch any log events containing
* our subdomain name and send them to our launcher lambda.
*
* Java supports SRV records so we can create a more precise filter
* unfortunately Minecraft Bedrock does not support this yet.
*/
const dnsFilterPattern = config.minecraftEdition === "java"
? `_minecraft._tcp.${config.subdomainPart}.${config.domainName}`
: subdomain;

queryLogGroup.addSubscriptionFilter('SubscriptionFilter', {
destination: new logDestinations.LambdaDestination(launcherLambda),
filterPattern: logs.FilterPattern.anyTerm(subdomain),
filterPattern: logs.FilterPattern.anyTerm(dnsFilterPattern),
});

/**
Expand All @@ -151,7 +141,7 @@ export class DomainStack extends Stack {
allowedPattern: '.*',
description: 'Hosted zone ID for minecraft server',
parameterName: constants.HOSTED_ZONE_SSM_PARAMETER,
stringValue: subdomainHostedZone.hostedZoneId,
stringValue: rootHostedZone.hostedZoneId,
});

/**
Expand Down
4 changes: 2 additions & 2 deletions cdk/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Protocol } from 'aws-cdk-lib/lib/aws-ecs';
import type { Port } from 'aws-cdk-lib/lib/aws-ec2';
import type { Protocol } from 'aws-cdk-lib/aws-ecs';
import type { Port } from 'aws-cdk-lib/aws-ec2';

interface TwilioConfig {
/**
Expand Down
4 changes: 2 additions & 2 deletions cdk/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Port } from 'aws-cdk-lib/lib/aws-ec2';
import { Protocol } from 'aws-cdk-lib/lib/aws-ecs';
import { Port } from 'aws-cdk-lib/aws-ec2';
import { Protocol } from 'aws-cdk-lib/aws-ecs';
import * as execa from 'execa';
import { constants } from './constants';
import { MinecraftEditionConfig, StackConfig } from './types';
Expand Down
Loading