diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts index e23ffdacc2f9a..abfeae0b015e9 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts @@ -179,6 +179,10 @@ export class ApplicationListenerRule extends cdk.Construct { throw new Error(`'${providedActions}' specified together, specify only one`); } + if (props.priority <= 0) { + throw new Error('Priority must have value greater than or equal to 1'); + } + this.listener = props.listener; const resource = new CfnListenerRule(this, 'Resource', { diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts index e1efd52ade154..e1a347a6af986 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/test/alb/test.listener.ts @@ -773,6 +773,30 @@ export = { test.done(); }, + 'Throws when specifying priority 0'(test: Test) { + // 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 + test.throws(() => new elbv2.ApplicationListenerRule(stack, 'Rule', { + listener, + priority: 0, + pathPattern: '/hello', + fixedResponse: { + statusCode: '500' + } + }), Error, 'Priority must have value greater than or equal to 1'); + + test.done(); + }, + 'Throws when specifying both target groups and redirect reponse'(test: Test) { // GIVEN const stack = new cdk.Stack();