-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
120 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,77 @@ | ||
import cdk = require('@aws-cdk/core'); | ||
import ec2 = require('@aws-cdk/aws-ec2') | ||
import { SubnetType, Vpc } from '@aws-cdk/aws-ec2' | ||
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); | ||
import autoscaling = require('@aws-cdk/aws-autoscaling'); | ||
import { App, Stack, StackProps, Tag } from '@aws-cdk/core' | ||
import { AmazonLinuxImage, InstanceSize, InstanceType, PublicSubnet, SubnetType, Vpc } from '@aws-cdk/aws-ec2' | ||
import { ApplicationLoadBalancer } from '@aws-cdk/aws-elasticloadbalancingv2' | ||
import { AutoScalingGroup } from '@aws-cdk/aws-autoscaling' | ||
|
||
export class CdkWorkshopStack extends cdk.Stack { | ||
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { | ||
super(scope, id, props); | ||
export class CdkWorkshopStack extends Stack { | ||
constructor(scope: App, id: string, props?: StackProps) { | ||
super(scope, id, props) | ||
|
||
const vpc = new Vpc(this, 'VPC', { | ||
cidr: '10.0.0.0/16', | ||
subnetConfiguration: [ | ||
{ | ||
cidrMask: 24, | ||
name: 'PublicSubnet1', | ||
name: 'Empty', | ||
subnetType: SubnetType.PUBLIC, | ||
cidrMask: 25, | ||
reserved: true | ||
}, | ||
{ | ||
name: 'Public', | ||
subnetType: SubnetType.PUBLIC, | ||
cidrMask: 24, | ||
// reserved: true | ||
}, | ||
], | ||
// { | ||
// name: 'Private', | ||
// subnetType: SubnetType.PRIVATE, | ||
// cidrMask: 24 | ||
// } | ||
] | ||
}) | ||
|
||
const lb = new elbv2.ApplicationLoadBalancer(this, 'PublicAlb', { | ||
vpc, | ||
internetFacing: true | ||
const selection = vpc.selectSubnets({ | ||
subnetType: SubnetType.PUBLIC | ||
}); | ||
|
||
/* | ||
* @see | ||
* https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-ec2/lib/vpc.ts#L1158 | ||
*/ | ||
// const publicSubnet = new PublicSubnet(this, 'PublicLLL', { | ||
// availabilityZone: vpc.availabilityZones[0], | ||
// cidrBlock: '10.0.1.0/24', | ||
// vpcId: vpc.vpcId | ||
// }) | ||
// vpc.publicSubnets.push(publicSubnet) | ||
|
||
|
||
const lb = new ApplicationLoadBalancer(this, 'PublicAlb', { | ||
vpc, | ||
internetFacing: true | ||
}) | ||
|
||
const listener = lb.addListener('Listener', { | ||
port: 80, | ||
open: true, | ||
port: 80, | ||
open: true | ||
}) | ||
|
||
const asg = new autoscaling.AutoScalingGroup(this, 'TargetFleetAutoScalingGroup', { | ||
vpc, | ||
instanceType: new ec2.InstanceType(ec2.InstanceSize.SMALL), | ||
machineImage: new ec2.AmazonLinuxImage() | ||
const asg = new AutoScalingGroup(this, 'TargetFleetAutoScalingGroup', { | ||
vpc, | ||
instanceType: new InstanceType(InstanceSize.SMALL), | ||
machineImage: new AmazonLinuxImage() | ||
}) | ||
|
||
listener.addTargets('TargetFleetTg', { | ||
port: 8080, | ||
targets: [asg] | ||
port: 8080, | ||
targets: [asg] | ||
}) | ||
|
||
;[ | ||
vpc, | ||
lb, | ||
listener, | ||
asg | ||
].forEach(construct => Tag.add(construct, 'Application', id)) | ||
} | ||
} |