Skip to content

Commit

Permalink
fix(elbv2): unresolved listener priority throws error (aws#15804)
Browse files Browse the repository at this point in the history
Fixes an issue where unresolved Listener `priority` would resolve in Error: `Priority must have value greater than or equal to 1`.

This adds support for cases where the Listener `priority` can be supplied through CloudFormation Template Parameters.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
spg authored and david-doyle-as24 committed Sep 7, 2021
1 parent 5199c25 commit 1fcbaaa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class ApplicationListenerRule extends CoreConstruct {
throw new Error(`'${providedActions}' specified together, specify only one`);
}

if (props.priority <= 0) {
if (!cdk.Token.isUnresolved(props.priority) && props.priority <= 0) {
throw new Error('Priority must have value greater than or equal to 1');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,28 @@ describe('tests', () => {
})).toThrowError('Priority must have value greater than or equal to 1');
});

test('Accepts unresolved priority', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const lb = new elbv2.ApplicationLoadBalancer(stack, 'LoadBalancer', {
vpc,
});
const listener = lb.addListener('Listener', {
port: 80,
});

// THEN
expect(() => new elbv2.ApplicationListenerRule(stack, 'Rule', {
listener,
priority: new cdk.CfnParameter(stack, 'PriorityParam', { type: 'Number' }).valueAsNumber,
pathPattern: '/hello',
fixedResponse: {
statusCode: '500',
},
})).not.toThrowError('Priority must have value greater than or equal to 1');
});

test('Throws when specifying both target groups and redirect response', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 1fcbaaa

Please sign in to comment.