Skip to content

Commit 9add107

Browse files
authored
Merge pull request #8 from RoundingWellOS/feature/addElbResourceSuppport
Feature/add elb resource suppport
2 parents f17ae31 + 045be7c commit 9add107

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ custom:
6666
my-task-with-load-balancers:
6767
image: 123456789369.dkr.ecr.eu-west-1.amazonaws.com/my-image
6868
loadBalancers:
69-
- port: 8080
70-
arn: ${self:custom.httpTargetGroupArn}
71-
- port 8443
72-
arn: ${self:custom.httpsTargetGroupArn}
69+
# You can use the arn of an existing target group already associated with a load balancer
70+
- hostPort: 8080
71+
containerPort: 8080
72+
targetGroup: ${self:custom.httpTargetGroupArn}
73+
# If you're using an ELB/target group that you're building in the Resources section of
74+
# serverless.yml, you may run into an issue where the elb and default listener rule are
75+
# not created prior to the target group/service. In this scenario you can specify the
76+
# logical name of the resource so that the appropriate dependencies can be set.
77+
- hostPort: 8443
78+
containerPort: 8443
79+
targetGroup: ${self:custom.httpsTargetGroupArn}
80+
elbResource: "my-task-elb"
7381
```
7482

7583
Advanced usage

lib/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,21 @@ class ServerlessFargateTasks {
174174
// Configure Load Balancers if defined.
175175
if(options.tasks[identifier].hasOwnProperty('loadBalancers')) {
176176
let loadBalancers = [];
177+
let dependsOn = [];
177178
options.tasks[identifier]['loadBalancers'].forEach(item => {
178179
const loadBalancer = Object.assign({
179180
'ContainerName': name,
180181
'ContainerPort': item.containerPort,
181-
'TargetGroupArn': item.arn
182+
'TargetGroupArn': item.targetGroup
182183
});
183184
loadBalancers.push(loadBalancer);
185+
if(item.hasOwnProperty('elbResource')) {
186+
dependsOn.push(item.elbResource)
187+
}
184188
});
189+
if(dependsOn.length > 0) {
190+
service['DependsOn'] = dependsOn;
191+
}
185192
service['Properties']['LoadBalancers'] = loadBalancers;
186193
}
187194
template['Resources'][normalizedIdentifier + 'Service'] = service

0 commit comments

Comments
 (0)