Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down