From a59bd2aa4f59ae49e981e3660088bf84793a3847 Mon Sep 17 00:00:00 2001 From: Ben Tennant Date: Tue, 12 Jan 2021 13:40:36 -0600 Subject: [PATCH 1/2] Add support for refs to dependent Elbs --- lib/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index dd06102..52e7ea1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -174,14 +174,21 @@ class ServerlessFargateTasks { // Configure Load Balancers if defined. if(options.tasks[identifier].hasOwnProperty('loadBalancers')) { let loadBalancers = []; + let dependsOn = []; options.tasks[identifier]['loadBalancers'].forEach(item => { const loadBalancer = Object.assign({ 'ContainerName': name, 'ContainerPort': item.containerPort, - 'TargetGroupArn': item.arn + 'TargetGroupArn': item.targetGroup }); loadBalancers.push(loadBalancer); + if(item.hasOwnProperty('elbResource')) { + dependsOn.push(item.elbResource) + } }); + if(dependsOn.length > 0) { + service['DependsOn'] = dependsOn; + } service['Properties']['LoadBalancers'] = loadBalancers; } template['Resources'][normalizedIdentifier + 'Service'] = service From 045be7c93269ecc3acaea791ce2ef277b33f395f Mon Sep 17 00:00:00 2001 From: Ben Tennant Date: Tue, 12 Jan 2021 16:35:36 -0600 Subject: [PATCH 2/2] Update README --- README.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49719e3..a31d57f 100644 --- a/README.md +++ b/README.md @@ -66,10 +66,18 @@ custom: my-task-with-load-balancers: image: 123456789369.dkr.ecr.eu-west-1.amazonaws.com/my-image loadBalancers: - - port: 8080 - arn: ${self:custom.httpTargetGroupArn} - - port 8443 - arn: ${self:custom.httpsTargetGroupArn} + # You can use the arn of an existing target group already associated with a load balancer + - hostPort: 8080 + containerPort: 8080 + targetGroup: ${self:custom.httpTargetGroupArn} + # If you're using an ELB/target group that you're building in the Resources section of + # serverless.yml, you may run into an issue where the elb and default listener rule are + # not created prior to the target group/service. In this scenario you can specify the + # logical name of the resource so that the appropriate dependencies can be set. + - hostPort: 8443 + containerPort: 8443 + targetGroup: ${self:custom.httpsTargetGroupArn} + elbResource: "my-task-elb" ``` Advanced usage