question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(ElasticLoadBalancingV2): CDK to automatically calculate priority for host-based load balancer rules

See original GitHub issue

Use Case

When creating a host-based load balancer rule, I really don’t care about the rule priority because I rely on exact matches, so I don’t want to have to keep track of the priority values and make sure I don’t try to set the same value twice or else I’ll get an error on deployment. I realize this is a problem with AWS itself (it should really be fixed there so no one would have to do anything custom like today), but other tools like Terraform have solved this problem internally so that the end user doesn’t have to care about it. It would be great if CDK did this by default as well, and the user would provide the value if there’s an exception to the rule.

Desired behavior:

When creating a load balancer rule like this:

        ApplicationListenerRule.Builder.create(this, "Listener Rule")
            .action(ListenerAction.forward(listOf(defaultTargetGroup)))
            .conditions(listOf(ListenerCondition.hostHeaders(listOf(hostName))))
            .listener(httpsListener)
            .priority(1)
            .build()

I shouldn’t have to add the priority myself as I don’t rely on priority matches when using host-based rules.


This is a 🚀 Feature Request

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:14
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
Kazperscommented, Sep 26, 2022

Is there anything new on this one @ericzbeard @rix0rrr or others? It’s a serious deficiency (although I know it’s the fault of underlying AWS, not cdk), that makes it extremely hard to use CDK for deployments involving multiple listener rules. We really don’t want to micro-manage priority for hundreds of services that each have a forward rule on the ALBs…

The workaround with hashes is… fragile. I appreciate it as a temporary measure, but I really don’t want fragility in my ops deployments…

4reactions
metametadatacommented, Mar 30, 2022

Our current workaround is to assign a priority based on hashing the rule’s unique ID. In Clojure:

rule-id (str domain "-rule")
priority (mod (hash rule-id) 50001) ; Range: 0-50000

...

(-> (ApplicationListenerRule$Builder/create stack rule-id)
     ...
     (.conditions [(ListenerCondition/hostHeaders [domain])])
     (.priority priority)
     .build)

It’s prone to hash collisions but we were lucky so far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-elasticloadbalancingv2 module
Application and Network Load Balancers organize load balancing targets in Target Groups. If you add your balancing targets (such as AutoScalingGroups, ECS ...
Read more >
AWS CDK - Existing Application Load Balancer Listener
The aim is to have existing rules priority start with N + 1. Where N is the current count of rules. Doing so...
Read more >
ALB host-header rules with priority in cloudformation - Reddit
In ALB listener rules, each rule has to have a unique priority and the priority attribute is mandatory in the AWS::ElasticLoadBalancingV2:: ...
Read more >
tion in Amazon Web Ser- vices with Traffic Mirror- ing and ...
fic Mirroring, VPC, Load Balancing and Auto-scaling can be utilized ... listener rules with order of priority to determine which one applies.
Read more >
software.amazon.awscdk.services.elasticloadbalancingv2 ...
Amazon Elastic Load Balancing V2 Construct Library. Stability: Stable. The @aws-cdk/aws-elasticloadbalancingv2 package provides constructs for configuring ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found