Skip to content

Commit

Permalink
feat(ec2): add support for vpc endpoints (#2104)
Browse files Browse the repository at this point in the history
Add support for both gateway and interface VPC endpoints. Static members are
exposed for all AWS service endpoints.

As gateway endpoints reference route tables, they currently cannot be added to
imported VPC networks.

BREAKING CHANGE: 

* `vpc.selectSubnetIds(...)` has been replaced with `vpc.selectSubnets(...).subnetIds`.
  • Loading branch information
jogold authored and rix0rrr committed Apr 9, 2019
1 parent 1e8f938 commit bbb3f34
Show file tree
Hide file tree
Showing 18 changed files with 1,756 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class AutoScalingGroup extends cdk.Construct implements IAutoScalingGroup
throw new Error(`Should have minCapacity (${minCapacity}) <= desiredCapacity (${desiredCapacity}) <= maxCapacity (${maxCapacity})`);
}

const subnetIds = props.vpc.subnetIds(props.vpcSubnets);
const { subnetIds } = props.vpc.selectSubnets(props.vpcSubnets);
const asgProps: CfnAutoScalingGroupProps = {
cooldown: props.cooldownSeconds !== undefined ? `${props.cooldownSeconds}` : undefined,
minSize: minCapacity.toString(),
Expand Down
5 changes: 1 addition & 4 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -879,9 +879,6 @@ export class Project extends ProjectBase {
});
this._securityGroups = [securityGroup];
}
const subnetSelection: ec2.SubnetSelection = props.subnetSelection ? props.subnetSelection : {
subnetType: ec2.SubnetType.Private
};
this.addToRoleInlinePolicy(new iam.PolicyStatement()
.addAllResources()
.addActions(
Expand All @@ -904,7 +901,7 @@ export class Project extends ProjectBase {
.addAction('ec2:CreateNetworkInterfacePermission'));
return {
vpcId: props.vpc.vpcId,
subnets: props.vpc.subnetIds(subnetSelection).map(s => s),
subnets: props.vpc.selectSubnets(props.subnetSelection).subnetIds,
securityGroupIds: this._securityGroups.map(s => s.securityGroupId)
};
}
Expand Down
7 changes: 7 additions & 0 deletions packages/@aws-cdk/aws-ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,10 @@ const vpnConnection = vpc.addVpnConnection('Dynamic', {
});
const state = vpnConnection.metricTunnelState();
```

### VPC endpoints
A VPC endpoint enables you to privately connect your VPC to supported AWS services and VPC endpoint services powered by PrivateLink without requiring an internet gateway, NAT device, VPN connection, or AWS Direct Connect connection. Instances in your VPC do not require public IP addresses to communicate with resources in the service. Traffic between your VPC and the other service does not leave the Amazon network.

Endpoints are virtual devices. They are horizontally scaled, redundant, and highly available VPC components that allow communication between instances in your VPC and services without imposing availability risks or bandwidth constraints on your network traffic.

[example of setting up VPC endpoints](test/integ.vpc-endpoint.lit.ts)
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-ec2/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './vpc';
export * from './vpc-ref';
export * from './vpc-network-provider';
export * from './vpn';
export * from './vpc-endpoint';

// AWS::EC2 CloudFormation Resources:
export * from './ec2.generated';
Expand Down
Loading

0 comments on commit bbb3f34

Please sign in to comment.