Skip to content

Commit 0180249

Browse files
authored
Merge branch 'master' into conroy/fixtemplate
2 parents bd60ceb + dc7533c commit 0180249

219 files changed

Lines changed: 1606 additions & 266 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/team-owners-assignment.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/@aws-cdk/aws-cloudwatch/lib/metric-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export enum Unit {
216216
COUNT_PER_SECOND = 'Count/Second',
217217

218218
/**
219-
* No unit
219+
* None
220220
*/
221221
NONE = 'None'
222222
}

packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { INetworkLoadBalancer, NetworkListener, NetworkLoadBalancer, NetworkTarg
77
import { IRole } from '@aws-cdk/aws-iam';
88
import { ARecord, CnameRecord, IHostedZone, RecordTarget } from '@aws-cdk/aws-route53';
99
import { LoadBalancerTarget } from '@aws-cdk/aws-route53-targets';
10-
import * as cdk from '@aws-cdk/core';
10+
import { CfnOutput, Duration, FeatureFlags, Stack } from '@aws-cdk/core';
11+
import { ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT } from '@aws-cdk/cx-api';
1112
import { Construct } from 'constructs';
1213

1314
// keep this import separate from other imports to reduce chance for merge conflicts with v2-main
@@ -103,7 +104,7 @@ export interface NetworkLoadBalancedServiceBaseProps {
103104
*
104105
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
105106
*/
106-
readonly healthCheckGracePeriod?: cdk.Duration;
107+
readonly healthCheckGracePeriod?: Duration;
107108

108109
/**
109110
* The maximum number of tasks, specified as a percentage of the Amazon ECS
@@ -347,7 +348,7 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
347348
const loadBalancer = props.loadBalancer ?? new NetworkLoadBalancer(this, 'LB', lbProps);
348349
const listenerPort = props.listenerPort ?? 80;
349350
const targetProps = {
350-
port: props.taskImageOptions?.containerPort ?? 80,
351+
port: FeatureFlags.of(this).isEnabled(ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT) ? props.taskImageOptions?.containerPort ?? 80 : 80,
351352
};
352353

353354
this.listener = loadBalancer.addListener('PublicListener', { port: listenerPort });
@@ -384,7 +385,7 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
384385
}
385386

386387
if (props.loadBalancer === undefined) {
387-
new cdk.CfnOutput(this, 'LoadBalancerDNS', { value: this.loadBalancer.loadBalancerDnsName });
388+
new CfnOutput(this, 'LoadBalancerDNS', { value: this.loadBalancer.loadBalancerDnsName });
388389
}
389390
}
390391

@@ -394,7 +395,7 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
394395
protected getDefaultCluster(scope: CoreConstruct, vpc?: IVpc): Cluster {
395396
// magic string to avoid collision with user-defined constructs
396397
const DEFAULT_CLUSTER_ID = `EcsDefaultClusterMnL3mNNYN${vpc ? vpc.node.id : ''}`;
397-
const stack = cdk.Stack.of(scope);
398+
const stack = Stack.of(scope);
398399
return stack.node.tryFindChild(DEFAULT_CLUSTER_ID) as Cluster || new Cluster(stack, DEFAULT_CLUSTER_ID, { vpc });
399400
}
400401

packages/@aws-cdk/aws-ecs-patterns/lib/base/network-multiple-target-groups-service-base.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import { NetworkListener, NetworkLoadBalancer, NetworkTargetGroup } from '@aws-c
77
import { IRole } from '@aws-cdk/aws-iam';
88
import { ARecord, IHostedZone, RecordTarget } from '@aws-cdk/aws-route53';
99
import { LoadBalancerTarget } from '@aws-cdk/aws-route53-targets';
10-
import { CfnOutput, Duration, Stack } from '@aws-cdk/core';
10+
import { CfnOutput, Duration, FeatureFlags, Stack } from '@aws-cdk/core';
11+
import { ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT } from '@aws-cdk/cx-api';
1112
import { Construct } from 'constructs';
1213

1314
// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
@@ -374,7 +375,7 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru
374375
protected registerECSTargets(service: BaseService, container: ContainerDefinition, targets: NetworkTargetProps[]): NetworkTargetGroup {
375376
for (const targetProps of targets) {
376377
const targetGroup = this.findListener(targetProps.listener).addTargets(`ECSTargetGroup${container.containerName}${targetProps.containerPort}`, {
377-
port: targetProps.containerPort ?? 80,
378+
port: FeatureFlags.of(this).isEnabled(ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT) ? targetProps.containerPort ?? 80 : 80,
378379
targets: [
379380
service.loadBalancerTarget({
380381
containerName: container.containerName,

packages/@aws-cdk/aws-ecs-patterns/test/fargate/load-balanced-fargate-service-v2.test.ts

Lines changed: 145 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Vpc } from '@aws-cdk/aws-ec2';
33
import * as ecs from '@aws-cdk/aws-ecs';
44
import { ContainerImage } from '@aws-cdk/aws-ecs';
55
import { CompositePrincipal, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
6-
import { Duration, Stack } from '@aws-cdk/core';
6+
import { testFutureBehavior, testLegacyBehavior } from '@aws-cdk/cdk-build-tools';
7+
import { App, Duration, Stack } from '@aws-cdk/core';
8+
import { ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT } from '@aws-cdk/cx-api';
79
import { ApplicationLoadBalancedFargateService, ApplicationMultipleTargetGroupsFargateService, NetworkLoadBalancedFargateService, NetworkMultipleTargetGroupsFargateService } from '../../lib';
810

911
describe('When Application Load Balancer', () => {
@@ -663,9 +665,36 @@ describe('When Network Load Balancer', () => {
663665
}).toThrow(/You must specify one of: taskDefinition or image/);
664666
});
665667

666-
test('test Fargate networkloadbalanced construct with custom Port', () => {
668+
testLegacyBehavior('Fargate neworkloadbalanced construct uses Port 80 for target group when feature flag is not enabled', App, (app) => {
667669
// GIVEN
668-
const stack = new Stack();
670+
const stack = new Stack(app);
671+
const vpc = new Vpc(stack, 'VPC');
672+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
673+
674+
new NetworkLoadBalancedFargateService(stack, 'NLBService', {
675+
cluster: cluster,
676+
memoryLimitMiB: 1024,
677+
cpu: 512,
678+
taskImageOptions: {
679+
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
680+
containerPort: 81,
681+
},
682+
listenerPort: 8181,
683+
});
684+
685+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
686+
Port: 80,
687+
Protocol: 'TCP',
688+
TargetType: 'ip',
689+
VpcId: {
690+
Ref: 'VPCB9E5F0B4',
691+
},
692+
});
693+
});
694+
695+
testFutureBehavior('Fargate networkloadbalanced construct uses custom Port for target group when feature flag is enabled', { [ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT]: true }, App, (app) => {
696+
// GIVEN
697+
const stack = new Stack(app);
669698
const vpc = new Vpc(stack, 'VPC');
670699
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
671700

@@ -690,9 +719,79 @@ describe('When Network Load Balancer', () => {
690719
});
691720
});
692721

693-
test('test Fargate multinetworkloadbalanced construct with custom Port', () => {
722+
testFutureBehavior('Fargate networkloadbalanced construct uses 80 for target group when feature flag is enabled but container port is not provided', { [ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT]: true }, App, (app) => {
694723
// GIVEN
695-
const stack = new Stack();
724+
const stack = new Stack(app);
725+
const vpc = new Vpc(stack, 'VPC');
726+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
727+
728+
new NetworkLoadBalancedFargateService(stack, 'NLBService', {
729+
cluster: cluster,
730+
memoryLimitMiB: 1024,
731+
cpu: 512,
732+
taskImageOptions: {
733+
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
734+
},
735+
listenerPort: 8181,
736+
});
737+
738+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
739+
Port: 80,
740+
Protocol: 'TCP',
741+
TargetType: 'ip',
742+
VpcId: {
743+
Ref: 'VPCB9E5F0B4',
744+
},
745+
});
746+
});
747+
748+
testLegacyBehavior('Fargate multinetworkloadbalanced construct uses Port 80 for target group when feature flag is not enabled', App, (app) => {
749+
// GIVEN
750+
const stack = new Stack(app);
751+
const vpc = new Vpc(stack, 'VPC');
752+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
753+
754+
new NetworkMultipleTargetGroupsFargateService(stack, 'Service', {
755+
cluster,
756+
taskImageOptions: {
757+
image: ecs.ContainerImage.fromRegistry('test'),
758+
},
759+
});
760+
761+
762+
new NetworkMultipleTargetGroupsFargateService(stack, 'NLBService', {
763+
cluster: cluster,
764+
memoryLimitMiB: 1024,
765+
cpu: 512,
766+
taskImageOptions: {
767+
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
768+
},
769+
loadBalancers: [
770+
{
771+
name: 'lb1',
772+
listeners: [
773+
{ name: 'listener1', port: 8181 },
774+
],
775+
},
776+
],
777+
targetGroups: [{
778+
containerPort: 81,
779+
}],
780+
});
781+
782+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
783+
Port: 80,
784+
Protocol: 'TCP',
785+
TargetType: 'ip',
786+
VpcId: {
787+
Ref: 'VPCB9E5F0B4',
788+
},
789+
});
790+
});
791+
792+
testFutureBehavior('test Fargate multinetworkloadbalanced construct uses custom Port for target group when feature flag is enabled', { [ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT]: true }, App, (app) => {
793+
// GIVEN
794+
const stack = new Stack(app);
696795
const vpc = new Vpc(stack, 'VPC');
697796
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
698797

@@ -733,4 +832,45 @@ describe('When Network Load Balancer', () => {
733832
},
734833
});
735834
});
835+
836+
testFutureBehavior('test Fargate multinetworkloadbalanced construct uses 80 for target group when feature flag is enabled but container port is not provided', { [ECS_PATTERNS_TARGET_GROUP_PORT_FROM_CONTAINER_PORT]: true }, App, (app) => {
837+
// GIVEN
838+
const stack = new Stack(app);
839+
const vpc = new Vpc(stack, 'VPC');
840+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
841+
842+
new NetworkMultipleTargetGroupsFargateService(stack, 'Service', {
843+
cluster,
844+
taskImageOptions: {
845+
image: ecs.ContainerImage.fromRegistry('test'),
846+
},
847+
});
848+
849+
850+
new NetworkMultipleTargetGroupsFargateService(stack, 'NLBService', {
851+
cluster: cluster,
852+
memoryLimitMiB: 1024,
853+
cpu: 512,
854+
taskImageOptions: {
855+
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
856+
},
857+
loadBalancers: [
858+
{
859+
name: 'lb1',
860+
listeners: [
861+
{ name: 'listener1', port: 8181 },
862+
],
863+
},
864+
],
865+
});
866+
867+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
868+
Port: 80,
869+
Protocol: 'TCP',
870+
TargetType: 'ip',
871+
VpcId: {
872+
Ref: 'VPCB9E5F0B4',
873+
},
874+
});
875+
});
736876
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const baseConfig = require('@aws-cdk/cdk-build-tools/config/eslintrc');
2+
baseConfig.parserOptions.project = __dirname + '/tsconfig.json';
3+
module.exports = baseConfig;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
*.js
2+
*.js.map
3+
*.d.ts
4+
tsconfig.json
5+
node_modules
6+
*.generated.ts
7+
dist
8+
.jsii
9+
10+
.LAST_BUILD
11+
.nyc_output
12+
coverage
13+
.nycrc
14+
.LAST_PACKAGE
15+
*.snk
16+
nyc.config.js
17+
!.eslintrc.js
18+
!jest.config.js
19+
junit.xml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Don't include original .ts files when doing `npm pack`
2+
*.ts
3+
!*.d.ts
4+
coverage
5+
.nyc_output
6+
*.tgz
7+
8+
dist
9+
.LAST_PACKAGE
10+
.LAST_BUILD
11+
!*.js
12+
13+
# Include .jsii
14+
!.jsii
15+
16+
*.snk
17+
18+
*.tsbuildinfo
19+
20+
tsconfig.json
21+
22+
.eslintrc.js
23+
jest.config.js
24+
25+
# exclude cdk artifacts
26+
**/cdk.out
27+
junit.xml
28+
test/
29+
!*.lit.ts

0 commit comments

Comments
 (0)