-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code to use an existing listener
- Loading branch information
Showing
35 changed files
with
357 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
lib/plugins/aws/package/compile/events/alb/lib/listenerRules.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
const BbPromise = require('bluebird'); | ||
|
||
module.exports = { | ||
compileListenerRules() { | ||
this.validated.events.forEach((event) => { | ||
const listenerRuleLogicalId = this.provider.naming | ||
.getAlbListenerRuleLogicalId(event.functionName, event.priority); | ||
const targetGroupLogicalId = this.provider.naming | ||
.getAlbTargetGroupLogicalId(event.functionName); | ||
|
||
const Conditions = [ | ||
{ | ||
Field: 'path-pattern', | ||
Values: [event.conditions.path], | ||
}, | ||
]; | ||
if (event.conditions.host) { | ||
Conditions.push({ | ||
Field: 'host-header', | ||
Values: [event.conditions.host], | ||
}); | ||
} | ||
|
||
Object.assign(this.serverless.service.provider.compiledCloudFormationTemplate.Resources, { | ||
[listenerRuleLogicalId]: { | ||
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule', | ||
Properties: { | ||
Actions: [ | ||
{ | ||
Type: 'forward', | ||
TargetGroupArn: { | ||
Ref: targetGroupLogicalId, | ||
}, | ||
}, | ||
], | ||
Conditions, | ||
ListenerArn: event.listenerArn, | ||
Priority: event.priority, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
return BbPromise.resolve(); | ||
}, | ||
}; |
105 changes: 105 additions & 0 deletions
105
lib/plugins/aws/package/compile/events/alb/lib/listenerRules.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const AwsCompileAlbEvents = require('../index'); | ||
const Serverless = require('../../../../../../../Serverless'); | ||
const AwsProvider = require('../../../../../provider/awsProvider'); | ||
|
||
describe('#compileListenerRules()', () => { | ||
let awsCompileAlbEvents; | ||
|
||
beforeEach(() => { | ||
const serverless = new Serverless(); | ||
serverless.setProvider('aws', new AwsProvider(serverless)); | ||
serverless.service.service = 'some-service'; | ||
serverless.service.provider.compiledCloudFormationTemplate = { Resources: {} }; | ||
|
||
awsCompileAlbEvents = new AwsCompileAlbEvents(serverless); | ||
}); | ||
|
||
it('should create ELB listener rule resources', () => { | ||
awsCompileAlbEvents.validated = { | ||
events: [ | ||
{ | ||
functionName: 'first', | ||
// eslint-disable-next-line max-len | ||
listenerArn: 'arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2', | ||
priority: 1, | ||
conditions: { | ||
host: 'example.com', | ||
path: '/hello', | ||
}, | ||
}, | ||
{ | ||
functionName: 'second', | ||
// eslint-disable-next-line max-len | ||
listenerArn: 'arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2', | ||
priority: 2, | ||
conditions: { | ||
path: '/world', | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
return awsCompileAlbEvents.compileListenerRules().then(() => { | ||
const resources = awsCompileAlbEvents.serverless.service.provider | ||
.compiledCloudFormationTemplate.Resources; | ||
|
||
expect(resources.FirstAlbListenerRule1).to.deep.equal({ | ||
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule', | ||
Properties: { | ||
Actions: [ | ||
{ | ||
TargetGroupArn: { | ||
Ref: 'FirstAlbTargetGroup', | ||
}, | ||
Type: 'forward', | ||
}, | ||
], | ||
Conditions: [ | ||
{ | ||
Field: 'path-pattern', | ||
Values: [ | ||
'/hello', | ||
], | ||
}, | ||
{ | ||
Field: 'host-header', | ||
Values: [ | ||
'example.com', | ||
], | ||
}, | ||
], | ||
// eslint-disable-next-line max-len | ||
ListenerArn: 'arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2', | ||
Priority: 1, | ||
}, | ||
}); | ||
expect(resources.SecondAlbListenerRule2).to.deep.equal({ | ||
Type: 'AWS::ElasticLoadBalancingV2::ListenerRule', | ||
Properties: { | ||
Actions: [ | ||
{ | ||
TargetGroupArn: { | ||
Ref: 'SecondAlbTargetGroup', | ||
}, | ||
Type: 'forward', | ||
}, | ||
], | ||
Conditions: [ | ||
{ | ||
Field: 'path-pattern', | ||
Values: [ | ||
'/world', | ||
], | ||
}, | ||
], | ||
// eslint-disable-next-line max-len | ||
ListenerArn: 'arn:aws:elasticloadbalancing:us-east-1:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2', | ||
Priority: 2, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
52 changes: 0 additions & 52 deletions
52
lib/plugins/aws/package/compile/events/alb/lib/listeners.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.