Aws-cdk: Priority value for lb.addListener should be validated by CDK

Created on 26 Sep 2019  路  5Comments  路  Source: aws/aws-cdk

CDK should provide a synth time check to make sure that the priority value for a load balancer rule is not zero.

Use Case

When creating adding many targets to listeners I set priority to zero while looping through an array:

      listeners.forEach((listener, i) => {
        listener.addTargets(`Target${i}`, {
          pathPattern: `path-${i}`,
          priority: i,
          targets: [service],
          port: ports[i],
          protocol: elbv2.ApplicationProtocol.HTTP,
        });
      });

I was able to synth and diff without error. Then when I deployed I saw:

1 validation error detected: Value '0' at 'priority' failed to satisfy constraint: Member must have value greater than or equal to 1 (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: 79be03d3-3469-45c1-9dda-3e1e7049a6d6)

Proposed Solution

CDK should validate that priority !== 0 here.

  • [x] :wave: I may be able to implement this feature request
  • [ ] :warning: This feature might incur a breaking change

This is a :rocket: Feature Request

@aws-cdaws-elasticloadbalancing efforsmall feature-request

Most helpful comment

priority in ALB has long been an issue in various ways. Currently I'm using a lambda to return the next available priority, but ideally I'd like to just have to not specify it, and have CDK/CF choose a none conflicting priority for me. We may be unusual in that our patterns never overlap in any way so priority doesn't actually matter much, but maybe we're not that unusual in such a use case.

All 5 comments

priority in ALB has long been an issue in various ways. Currently I'm using a lambda to return the next available priority, but ideally I'd like to just have to not specify it, and have CDK/CF choose a none conflicting priority for me. We may be unusual in that our patterns never overlap in any way so priority doesn't actually matter much, but maybe we're not that unusual in such a use case.

I am using a Lambda too for this purpose and I am thinking to implement this into CDK for a while now. Good to see, that I am not alone.

@gary-cowell @hoegertn would either of you be able to share how you used the lambda in conjunction with CDK to achieve automatically incrementing to the next the listener rule priority? Did you use a custom resource?

I found these two answers on SO as potential starting points but no complete example with CDK:

Thanks!

I think I might have found what I'm looking for here: https://github.com/aws/aws-cdk/issues/9296

@gary-cowell @hoegertn would either of you be able to share how you used the lambda in conjunction with CDK to achieve automatically incrementing to the next the listener rule priority? Did you use a custom resource?

I found these two answers on SO as potential starting points but no complete example with CDK:

* https://stackoverflow.com/questions/50003378/automatically-set-listenerrule-priority-in-cloudformation-template

* https://stackoverflow.com/questions/63333765/priority-is-currently-in-use-when-deploying-cdk

Thanks!

What I eventually ended up doing, was to move some of the configuration out from CDK and into a dynamodb table. I made the primary key of the dynamodb table be an integer and used this as the rule priority, thus ensuring there were no duplicates. I changed my CDK project to read the dynamodb table at synth/deploy time and configure the ALB rules accordingly.

Was this page helpful?
0 / 5 - 0 ratings