Created
June 28, 2019 21:22
-
-
Save mrcustard/828242e3e5b8786776fd0c78d1e74e63 to your computer and use it in GitHub Desktop.
bin file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs = require('fs'); | |
import cdk = require('@aws-cdk/core'); | |
import ec2 = require('@aws-cdk/aws-ec2'); | |
import r53 = require('@aws-cdk/aws-route53'); | |
import asg = require('@aws-cdk/aws-autoscaling'); | |
import elb = require('@aws-cdk/aws-elasticloadbalancing'); | |
export interface MssymbolServerCdkStackProps extends cdk.StackProps { | |
readonly vpc: string; | |
readonly asg_minCapacity: number; | |
readonly asg_maxCapacity: number; | |
readonly asg_machineImage: ec2.WindowsImage; | |
readonly asg_instanceType: ec2.InstanceType; | |
readonly elb_healthCheck: elb.HealthCheck; | |
readonly elb_internetFacing: boolean; | |
readonly elb_Listeners: { externalPort: number }[]; | |
} | |
export class MssymbolServerCdkStack extends cdk.Stack { | |
private _vpc: ec2.IVpc; | |
private _asg: asg.AutoScalingGroup; | |
private _elb: elb.LoadBalancer; | |
private _defaultSecGroup: ec2.SecurityGroup; | |
private readonly _userData = fs.readFile('../scripts/userdata', function (err) { | |
if (err) { | |
console.log(err); | |
} | |
}); | |
constructor(scope: cdk.App, id: string, props: MssymbolServerCdkStackProps) { | |
super(scope, id, props); | |
this._vpc = ec2.Vpc.fromLookup(this, 'VPC', {vpcId: props.vpc}); | |
this._vpc.selectSubnets(); | |
// The code that defines your stack goes here | |
this._asg = new asg.AutoScalingGroup(this, 'ASG', { | |
vpc: this._vpc, | |
machineImage: props.asg_machineImage, | |
instanceType: props.asg_instanceType, | |
minCapacity: props.asg_minCapacity, | |
maxCapacity: props.asg_maxCapacity, | |
}); | |
this._defaultSecGroup = new ec2.SecurityGroup(this, 'DefaultAsgSecurityGroup', { | |
vpc: this._vpc, | |
securityGroupName: 'DefaultAsgSecurityGroup', | |
description: 'Allow to self', | |
allowAllOutbound: true | |
}); | |
this._defaultSecGroup.addIngressRule(this._defaultSecGroup, ec2.Port.allTraffic(), 'Allow self'); | |
this._defaultSecGroup.addEgressRule(ec2.Peer.anyIpv4(), ec2.Port.allTraffic(), 'Allow all egress'); | |
this._asg.addSecurityGroup(this._defaultSecGroup); | |
this._elb = new elb.LoadBalancer(this, 'Loadbalancer', { | |
vpc: this._vpc, | |
listeners: props.elb_Listeners, | |
internetFacing: props.elb_internetFacing, | |
healthCheck: props.elb_healthCheck | |
}); | |
this._asg.addUserData(String(this._userData)) | |
} | |
public get Elb(){ | |
return this._elb; | |
} | |
public get Asg() { | |
return this._asg; | |
} | |
public get DefaultSecGroup(){ | |
return this._defaultSecGroup; | |
} | |
} | |
export interface R53MssymbolServerProps extends cdk.StackProps { | |
readonly vpc: string; | |
readonly zoneName: string; | |
} | |
export class R53MssymbolServer extends cdk.Stack { | |
private _vpc: ec2.IVpc; | |
constructor(scope: cdk.App, id: string, props: R53MssymbolServerProps) { | |
super(scope, id, props); | |
this._vpc = ec2.Vpc.fromLookup(this, 'VPC', { vpcId: props.vpc }) | |
new r53.PrivateHostedZone(this, 'PrivateHostedZone', { | |
vpc: this._vpc, | |
zoneName: props.zoneName | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import 'source-map-support/register'; | |
import cdk = require('@aws-cdk/core'); | |
import ec2 = require('@aws-cdk/aws-ec2') | |
import { MssymbolServerCdkStack, R53MssymbolServer } from '../lib/mssymbol-server-cdk-stack'; | |
const app = new cdk.App(); | |
const serviceName = "MSSYMBOL"; | |
new R53MssymbolServer(app, `${serviceName}-R53-us-west-2`, { | |
vpc: '<vpc id>', | |
zoneName: 'mssymbol.internal.justin.tv' | |
}) | |
new MssymbolServerCdkStack(app, `${serviceName}-us-west-2`, { | |
env: { | |
region: 'us-west-2', | |
account: '<account number>' | |
}, | |
vpc: '<vpc id>', | |
asg_minCapacity: 1, | |
asg_maxCapacity: 2, | |
asg_machineImage: new ec2.WindowsImage(ec2.WindowsVersion.WINDOWS_SERVER_2016_ENGLISH_FULL_BASE), | |
asg_instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.LARGE), | |
elb_healthCheck: { | |
port: 80 | |
}, | |
elb_internetFacing: false, | |
elb_Listeners: [{ | |
externalPort: 80 | |
}] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment