Skip to content

Commit

Permalink
Merge branch 'master' into robertd/assertions-conditions-matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 21, 2022
2 parents 1ed3bea + 1393729 commit 5c286b9
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export abstract class NetworkLoadBalancedServiceBase extends CoreConstruct {
const loadBalancer = props.loadBalancer ?? new NetworkLoadBalancer(this, 'LB', lbProps);
const listenerPort = props.listenerPort ?? 80;
const targetProps = {
port: 80,
port: props.taskImageOptions?.containerPort ?? 80,
};

this.listener = loadBalancer.addListener('PublicListener', { port: listenerPort });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends CoreConstru
protected registerECSTargets(service: BaseService, container: ContainerDefinition, targets: NetworkTargetProps[]): NetworkTargetGroup {
for (const targetProps of targets) {
const targetGroup = this.findListener(targetProps.listener).addTargets(`ECSTargetGroup${container.containerName}${targetProps.containerPort}`, {
port: 80,
port: targetProps.containerPort ?? 80,
targets: [
service.loadBalancerTarget({
containerName: container.containerName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@
"myServicelb2listener2ECSTargetGroupweb90Group6841F924": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"Port": 80,
"Port": 90,
"Protocol": "TCP",
"TargetType": "ip",
"VpcId": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
"FargateNlbServiceLBPublicListenerECSGroup7501571D": {
"Type": "AWS::ElasticLoadBalancingV2::TargetGroup",
"Properties": {
"Port": 80,
"Port": 2015,
"Protocol": "TCP",
"TargetType": "ip",
"VpcId": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Match, Template } from '@aws-cdk/assertions';
import { Vpc } from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import { ContainerImage } from '@aws-cdk/aws-ecs';
import { CompositePrincipal, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import { Duration, Stack } from '@aws-cdk/core';
import { ApplicationMultipleTargetGroupsFargateService, NetworkMultipleTargetGroupsFargateService, ApplicationLoadBalancedFargateService } from '../../lib';
import { ApplicationLoadBalancedFargateService, ApplicationMultipleTargetGroupsFargateService, NetworkLoadBalancedFargateService, NetworkMultipleTargetGroupsFargateService } from '../../lib';

describe('When Application Load Balancer', () => {
test('test Fargate loadbalanced construct with default settings', () => {
Expand Down Expand Up @@ -661,4 +662,75 @@ describe('When Network Load Balancer', () => {
});
}).toThrow(/You must specify one of: taskDefinition or image/);
});

test('test Fargate networkloadbalanced construct with custom Port', () => {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

new NetworkLoadBalancedFargateService(stack, 'NLBService', {
cluster: cluster,
memoryLimitMiB: 1024,
cpu: 512,
taskImageOptions: {
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
containerPort: 81,
},
listenerPort: 8181,
});

Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
Port: 81,
Protocol: 'TCP',
TargetType: 'ip',
VpcId: {
Ref: 'VPCB9E5F0B4',
},
});
});

test('test Fargate multinetworkloadbalanced construct with custom Port', () => {
// GIVEN
const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });

new NetworkMultipleTargetGroupsFargateService(stack, 'Service', {
cluster,
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('test'),
},
});


new NetworkMultipleTargetGroupsFargateService(stack, 'NLBService', {
cluster: cluster,
memoryLimitMiB: 1024,
cpu: 512,
taskImageOptions: {
image: ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
loadBalancers: [
{
name: 'lb1',
listeners: [
{ name: 'listener1', port: 8181 },
],
},
],
targetGroups: [{
containerPort: 81,
}],
});

Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::TargetGroup', {
Port: 81,
Protocol: 'TCP',
TargetType: 'ip',
VpcId: {
Ref: 'VPCB9E5F0B4',
},
});
});
});

0 comments on commit 5c286b9

Please sign in to comment.