Skip to content

Commit

Permalink
BREAKING: move LoadBalancer to aws-elasticloadbalancing package (#705)
Browse files Browse the repository at this point in the history
This is where it should have been all along.
  • Loading branch information
rix0rrr committed Sep 13, 2018
1 parent 3a67d5d commit 4bd1cf2
Show file tree
Hide file tree
Showing 18 changed files with 444 additions and 110 deletions.
5 changes: 3 additions & 2 deletions examples/cdk-examples-typescript/ec2/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import autoscaling = require('@aws-cdk/aws-autoscaling');
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import cdk = require('@aws-cdk/cdk');

class AppWithVpc extends cdk.Stack {
Expand All @@ -14,7 +15,7 @@ class AppWithVpc extends cdk.Stack {
machineImage: new ec2.AmazonLinuxImage()
});

const clb = new ec2.ClassicLoadBalancer(this, 'LB', {
const clb = new elb.LoadBalancer(this, 'LB', {
vpc,
internetFacing: true
});
Expand All @@ -40,7 +41,7 @@ class MyApp extends cdk.Stack {
machineImage: new ec2.AmazonLinuxImage()
});

const clb = new ec2.ClassicLoadBalancer(this, 'LB', {
const clb = new elb.LoadBalancer(this, 'LB', {
vpc,
internetFacing: true
});
Expand Down
1 change: 1 addition & 0 deletions examples/cdk-examples-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@aws-cdk/aws-cognito": "^0.9.0",
"@aws-cdk/aws-dynamodb": "^0.9.0",
"@aws-cdk/aws-ec2": "^0.9.0",
"@aws-cdk/aws-elasticloadbalancing": "^0.9.0",
"@aws-cdk/aws-iam": "^0.9.0",
"@aws-cdk/aws-lambda": "^0.9.0",
"@aws-cdk/aws-neptune": "^0.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// until we have that.
import autoscaling = require('@aws-cdk/aws-autoscaling');
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import cdk = require('@aws-cdk/cdk');

const app = new cdk.App(process.argv);
Expand All @@ -24,7 +25,7 @@ const asg = new autoscaling.AutoScalingGroup(appStack, 'ASG', {
machineImage: new ec2.AmazonLinuxImage()
});

new ec2.ClassicLoadBalancer(appStack, 'LB', {
new elb.LoadBalancer(appStack, 'LB', {
vpc: importedVpc,
internetFacing: true,
listeners: [{
Expand Down
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import iam = require('@aws-cdk/aws-iam');
import sns = require('@aws-cdk/aws-sns');
import cdk = require('@aws-cdk/cdk');
Expand Down Expand Up @@ -135,7 +136,7 @@ export interface AutoScalingGroupProps {
*
* The ASG spans all availability zones.
*/
export class AutoScalingGroup extends cdk.Construct implements ec2.IClassicLoadBalancerTarget, ec2.IConnectable {
export class AutoScalingGroup extends cdk.Construct implements elb.ILoadBalancerTarget, ec2.IConnectable {
/**
* The type of OS instances of this fleet are running.
*/
Expand Down Expand Up @@ -240,7 +241,7 @@ export class AutoScalingGroup extends cdk.Construct implements ec2.IClassicLoadB
this.securityGroups.push(securityGroup);
}

public attachToClassicLB(loadBalancer: ec2.ClassicLoadBalancer): void {
public attachToClassicLB(loadBalancer: elb.LoadBalancer): void {
this.loadBalancerNames.push(loadBalancer.loadBalancerName);
}

Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-autoscaling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"dependencies": {
"@aws-cdk/aws-ec2": "^0.9.0",
"@aws-cdk/aws-iam": "^0.9.0",
"@aws-cdk/aws-elasticloadbalancing": "^0.9.0",
"@aws-cdk/aws-sns": "^0.9.0",
"@aws-cdk/cdk": "^0.9.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import ec2 = require('@aws-cdk/aws-ec2');
import elb = require('@aws-cdk/aws-elasticloadbalancing');
import cdk = require('@aws-cdk/cdk');
import autoscaling = require('../lib');

Expand All @@ -16,17 +17,15 @@ const asg = new autoscaling.AutoScalingGroup(stack, 'Fleet', {
machineImage: new ec2.AmazonLinuxImage(),
});

new ec2.ClassicLoadBalancer(stack, 'LB', {
const lb = new elb.LoadBalancer(stack, 'LB', {
vpc,
internetFacing: true,
listeners: [{
externalPort: 80,
allowConnectionsFrom: [new ec2.AnyIPv4()]
}],
healthCheck: {
port: 80
},
targets: [asg]
});

lb.addTarget(asg);
lb.addListener({ externalPort: 80 });

process.stdout.write(app.run());
28 changes: 2 additions & 26 deletions packages/@aws-cdk/aws-ec2/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## AWS Compute and Networking Construct Library

The `@aws-cdk/aws-ec2` package contains primitives for setting up networking,
instances, and load balancers.
The `@aws-cdk/aws-ec2` package contains primitives for setting up networking and
instances.

### VPC

Expand Down Expand Up @@ -172,30 +172,6 @@ The `VpcNetwork` above will have the exact same subnet definitions as listed
above. However, this time the VPC will have only 1 NAT Gateway and all
Application subnets will route to the NAT Gateway.


### Load Balancer

Load balancers send traffic to one or more fleets. Create a load balancer,
set up listeners and a health check, and supply the fleet(s) you want to load
balance to in the `targets` property.

The load balancer allows all connections by default. If you want to change that,
pass the `allowConnectionsFrom` property while setting up the listener.

```ts
new ec2.ClassicLoadBalancer(stack, 'LB', {
vpc,
internetFacing: true,
listeners: [{
externalPort: 80,
}],
healthCheck: {
port: 80
},
targets: [fleet]
});
```

### Allowing Connections

In AWS, all connections to and from EC2 instances are governed by *Security
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-ec2/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './connections';
export * from './instance-types';
export * from './load-balancer';
export * from './machine-image';
export * from './security-group';
export * from './security-group-rule';
Expand Down
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-ec2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"pkglint": "^0.9.0"
},
"dependencies": {
"@aws-cdk/aws-elasticloadbalancing": "^0.9.0",
"@aws-cdk/aws-iam": "^0.9.0",
"@aws-cdk/cdk": "^0.9.0",
"@aws-cdk/util": "^0.9.0"
Expand Down
32 changes: 0 additions & 32 deletions packages/@aws-cdk/aws-ec2/test/test.loadbalancer.ts

This file was deleted.

37 changes: 35 additions & 2 deletions packages/@aws-cdk/aws-elasticloadbalancing/README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
## CDK Constructs for AWS Elastic Load Balancing (ELB)
This module is part of the [AWS Cloud Development Kit](https://github.com/awslabs/aws-cdk) project.
## AWS Elastic Load Balancing Construct Library

The `@aws-cdk/aws-ec2` package provides constructs for configuring
classic load balancers.

### Configuring a Load Balancer

Load balancers send traffic to one or more AutoScalingGroups. Create a load
balancer, set up listeners and a health check, and supply the fleet(s) you want
to load balance to in the `targets` property.

```ts
const lb = new elb.LoadBalancer(stack, 'LB', {
vpc,
internetFacing: true,
healthCheck: {
port: 80
},
});

lb.addTarget(myAutoScalingGroup);
lb.addListener({
externalPort: 80,
});
```

The load balancer allows all connections by default. If you want to change that,
pass the `allowConnectionsFrom` property while setting up the listener:

```
lb.addListener({
externalPort: 80,
allowConnectionsFrom: [mySecurityGroup]
});
```
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-elasticloadbalancing/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
// AWS::ElasticLoadBalancing CloudFormation Resources:
export * from './elasticloadbalancing.generated';

export * from './load-balancer';

0 comments on commit 4bd1cf2

Please sign in to comment.