-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ecs): vpc link for api gatway and load balanced services #1541
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { CfnVpcLink } from './apigateway.generated'; | ||
|
||
/** | ||
* Properties for a VpcLink | ||
*/ | ||
export interface VpcLinkProps { | ||
/** | ||
* The name used to label and identify the VPC link. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
name: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make this optional. If CloudFormation doesn't allow an optional name, you can always default inside the construct to |
||
|
||
/** | ||
* The description of the VPC link. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
*/ | ||
description?: string; | ||
|
||
/** | ||
* The network load balancers of the VPC targeted by the VPC link. | ||
* The network load balancers must be owned by the same AWS account of the API owner. | ||
*/ | ||
targets: elbv2.NetworkLoadBalancer[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should take |
||
} | ||
|
||
/** | ||
* Define a new VPC Link | ||
* Specifies an API Gateway VPC link for a RestApi to access resources in an Amazon Virtual Private Cloud (VPC). | ||
*/ | ||
export class VpcLink extends cdk.Construct { | ||
|
||
private readonly cfnResource: CfnVpcLink; | ||
|
||
constructor(scope: cdk.Construct, id: string, props: VpcLinkProps) { | ||
super(scope, id); | ||
|
||
this.cfnResource = new CfnVpcLink(this, 'Resource', { | ||
name: props.name, | ||
description: props.description, | ||
targetArns: props.targets.map(nlb => nlb.loadBalancerArn) | ||
}); | ||
} | ||
|
||
public get vpcLinkId() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but we generally just declare a string property on the construct and assign it in the constructor. |
||
return this.cfnResource.vpcLinkId; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { expect, haveResourceLike } from '@aws-cdk/assert'; | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import { Test } from 'nodeunit'; | ||
import apigateway = require('../lib'); | ||
|
||
export = { | ||
'default setup'(test: Test) { | ||
// GIVEN | ||
const stack = new cdk.Stack(); | ||
const vpc = new ec2.VpcNetwork(stack, 'VPC'); | ||
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', { | ||
vpc | ||
}); | ||
|
||
// WHEN | ||
new apigateway.VpcLink(stack, 'VpcLink', { | ||
name: 'MyLink', | ||
targets: [nlb] | ||
}); | ||
|
||
// THEN | ||
expect(stack).to(haveResourceLike('AWS::ApiGateway::VpcLink', { | ||
Name: "MyLink", | ||
TargetArns: [ { Ref: "NLB55158F82" } ] | ||
})); | ||
|
||
test.done(); | ||
}, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if connectiontype === internet and a vpcLink is supplied. Is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for ConnectionId state:
I took that to mean that it would just be ignored. Probably best to throw an error though to alert the user, since that's probably not what they wanted to happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was getting at. Thanks.