Skip to content

Commit

Permalink
Reduced to 50% the costs of AWS
Browse files Browse the repository at this point in the history
Reduced the cost of the AWS bill by only using 1 hosted zone instead of
2.

The cost is reduced from 1 eur month to 0.5 eur month with the same
functionality and no regression.
  • Loading branch information
AndresArcones authored and Colduck committed Apr 23, 2023
1 parent ea8673e commit be97df1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
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
25 changes: 4 additions & 21 deletions cdk/lib/domain-stack.ts
Original file line number Diff line number Diff line change
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 @@ -158,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

0 comments on commit be97df1

Please sign in to comment.