Skip to content
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(globalaccelerator): stabilize AWS Global Accelerator module #13843

Merged
merged 10 commits into from Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ec2/lib/peer.ts
Expand Up @@ -198,4 +198,4 @@ class PrefixList implements IPeer {
public toEgressRuleConfig(): any {
return { destinationPrefixListId: this.prefixListId };
}
}
}
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-ecs-patterns/test/ec2/test.l3s.ts
Expand Up @@ -1198,7 +1198,7 @@ export = {
'NetworkLoadBalancedEC2Service accepts imported load balancer'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const nlbArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const nlbArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const vpc = new ec2.Vpc(stack, 'Vpc');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc, clusterName: 'MyCluster' });
cluster.addCapacity('Capacity', { instanceType: new ec2.InstanceType('t2.micro') });
Expand Down Expand Up @@ -1274,7 +1274,7 @@ export = {
'ApplicationLoadBalancedEC2Service accepts imported load balancer'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const albArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const vpc = new ec2.Vpc(stack, 'Vpc');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc, clusterName: 'MyCluster' });
cluster.addCapacity('Capacity', { instanceType: new ec2.InstanceType('t2.micro') });
Expand Down
Expand Up @@ -810,7 +810,7 @@ export = {
const stack1 = new cdk.Stack(app, 'MyStack');
const vpc1 = new ec2.Vpc(stack1, 'VPC');
const cluster1 = new ecs.Cluster(stack1, 'Cluster', { vpc: vpc1 });
const nlbArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const nlbArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const stack2 = new cdk.Stack(stack1, 'Stack2');
const cluster2 = ecs.Cluster.fromClusterAttributes(stack2, 'ImportedCluster', {
vpc: vpc1,
Expand Down Expand Up @@ -887,7 +887,7 @@ export = {
'passing in imported application load balancer and resources to ALB Fargate Service'(test: Test) {
// GIVEN
const stack1 = new cdk.Stack();
const albArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const vpc = new ec2.Vpc(stack1, 'Vpc');
const cluster = new ecs.Cluster(stack1, 'Cluster', { vpc, clusterName: 'MyClusterName' });
const sg = new ec2.SecurityGroup(stack1, 'SecurityGroup', { vpc });
Expand Down
Expand Up @@ -562,7 +562,10 @@ class ImportedApplicationLoadBalancer extends Resource implements IApplicationLo
public readonly vpc?: ec2.IVpc;

constructor(scope: Construct, id: string, private readonly props: ApplicationLoadBalancerAttributes) {
super(scope, id);
super(scope, id, {
environmentFromArn: props.loadBalancerArn,
});

this.vpc = props.vpc;
this.loadBalancerArn = props.loadBalancerArn;
this.connections = new ec2.Connections({
Expand Down Expand Up @@ -601,7 +604,9 @@ class LookedUpApplicationLoadBalancer extends Resource implements IApplicationLo
public readonly vpc?: ec2.IVpc;

constructor(scope: Construct, id: string, props: cxapi.LoadBalancerContextResponse) {
super(scope, id);
super(scope, id, {
environmentFromArn: props.loadBalancerArn,
});

this.loadBalancerArn = props.loadBalancerArn;
this.loadBalancerCanonicalHostedZoneId = props.loadBalancerCanonicalHostedZoneId;
Expand Down
Expand Up @@ -102,7 +102,7 @@ export class NetworkLoadBalancer extends BaseLoadBalancer implements INetworkLoa
}
}

return new Import(scope, id);
return new Import(scope, id, { environmentFromArn: attrs.loadBalancerArn });
}

constructor(scope: Construct, id: string, props: NetworkLoadBalancerProps) {
Expand Down Expand Up @@ -306,7 +306,7 @@ class LookedUpNetworkLoadBalancer extends Resource implements INetworkLoadBalanc
public readonly vpc?: ec2.IVpc;

constructor(scope: Construct, id: string, props: cxapi.LoadBalancerContextResponse) {
super(scope, id);
super(scope, id, { environmentFromArn: props.loadBalancerArn });

this.loadBalancerArn = props.loadBalancerArn;
this.loadBalancerCanonicalHostedZoneId = props.loadBalancerCanonicalHostedZoneId;
Expand Down
Expand Up @@ -284,7 +284,7 @@ describe('tests', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const albArn = 'myArn';
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const sg = new ec2.SecurityGroup(stack, 'sg', {
vpc,
securityGroupName: 'mySg',
Expand All @@ -303,7 +303,7 @@ describe('tests', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const albArn = 'MyArn';
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const sg = new ec2.SecurityGroup(stack, 'sg', {
vpc,
securityGroupName: 'mySg',
Expand All @@ -319,6 +319,20 @@ describe('tests', () => {
expect(() => listener.addTargets('Targets', { port: 8080 })).not.toThrow();
});

test('imported load balancer knows its region', () => {
const stack = new cdk.Stack();

// WHEN
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const alb = elbv2.ApplicationLoadBalancer.fromApplicationLoadBalancerAttributes(stack, 'ALB', {
loadBalancerArn: albArn,
securityGroupId: 'sg-1234',
});

// THEN
expect(alb.env.region).toEqual('us-west-2');
});

test('can add secondary security groups', () => {
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Stack');
Expand Down Expand Up @@ -364,6 +378,7 @@ describe('tests', () => {
expect(loadBalancer.loadBalancerDnsName).toEqual('my-load-balancer-1234567890.us-west-2.elb.amazonaws.com');
expect(loadBalancer.ipAddressType).toEqual(elbv2.IpAddressType.DUAL_STACK);
expect(loadBalancer.connections.securityGroups[0].securityGroupId).toEqual('sg-12345');
expect(loadBalancer.env.region).toEqual('us-west-2');
});

test('Can add listeners to a looked-up ApplicationLoadBalancer', () => {
Expand Down
Expand Up @@ -227,7 +227,7 @@ describe('tests', () => {
test('imported network load balancer with no vpc specified throws error when calling addTargets', () => {
// GIVEN
const stack = new cdk.Stack();
const nlbArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const nlbArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const nlb = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(stack, 'NLB', {
loadBalancerArn: nlbArn,
});
Expand All @@ -240,7 +240,7 @@ describe('tests', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const nlbArn = 'arn:aws:elasticloadbalancing::000000000000::dummyloadbalancer';
const nlbArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const nlb = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(stack, 'NLB', {
loadBalancerArn: nlbArn,
vpc,
Expand All @@ -250,6 +250,19 @@ describe('tests', () => {
expect(() => listener.addTargets('targetgroup', { port: 8080 })).not.toThrow();
});

test('imported load balancer knows its region', () => {
const stack = new cdk.Stack();

// WHEN
const albArn = 'arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188';
const alb = elbv2.NetworkLoadBalancer.fromNetworkLoadBalancerAttributes(stack, 'ALB', {
loadBalancerArn: albArn,
});

// THEN
expect(alb.env.region).toEqual('us-west-2');
});

test('Trivial construction: internal with Isolated subnets only', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down Expand Up @@ -429,6 +442,7 @@ describe('tests', () => {
expect(loadBalancer.loadBalancerArn).toEqual('arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/network/my-load-balancer/50dc6c495c0c9188');
expect(loadBalancer.loadBalancerCanonicalHostedZoneId).toEqual('Z3DZXE0EXAMPLE');
expect(loadBalancer.loadBalancerDnsName).toEqual('my-load-balancer-1234567890.us-west-2.elb.amazonaws.com');
expect(loadBalancer.env.region).toEqual('us-west-2');
});

test('Can add listeners to a looked-up NetworkLoadBalancer', () => {
Expand Down
@@ -0,0 +1,3 @@
const baseConfig = require('cdk-build-tools/config/eslintrc');
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
module.exports = baseConfig;
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-globalaccelerator-endpoints/.gitignore
@@ -0,0 +1,22 @@
*.js
tsconfig.json
*.js.map
*.d.ts
*.generated.ts
dist
lib/generated/resources.ts
.jsii

.LAST_BUILD
.nyc_output
coverage
nyc.config.js
.LAST_PACKAGE
*.snk
.cdk.staging

lib/sdk-api-metadata.json
!.eslintrc.js
!jest.config.js

junit.xml
27 changes: 27 additions & 0 deletions packages/@aws-cdk/aws-globalaccelerator-endpoints/.npmignore
@@ -0,0 +1,27 @@
# Don't include original .ts files when doing `npm pack`
*.ts
!*.d.ts
coverage
.nyc_output
*.tgz

dist
.LAST_PACKAGE
.LAST_BUILD
!*.js

# Include .jsii
!.jsii

*.snk

*.tsbuildinfo

tsconfig.json
.eslintrc.js
jest.config.js

# exclude cdk artifacts
**/cdk.out
junit.xml
test/