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] Support References or CfnParameters in priority

See original GitHub issue

It would be great to be able to set the value of the priority dynamically using a Reference :

ApplicationListenerRule.Builder.create(stack, "ApplicationListenerRule")
                                .priority(token) // token.getValueAsNumber() does't work 
                                                 // since it generates a random number ( out of [0,50000] ) at synthesize stage
                                .build();
  • Actually I want to deploy the same ressoures defined in a stack in new stacks by setting the generated template in the service catalog ( there is a CFN parameter that will be used for the path but it’s not important ). Theses stacks uses the same ALB ( of another Stack ), and creates a new ALB Rule for the new ressources.

    I’m trying to recode this with CDK/java ( assuming I have a Lambda that generates the priority ) but it’s seems to be impossible

AllocateAlbRulePriorityCustomResource:
    Type: Custom::AllocateAlbRulePriority
    [...]

  ListenerRule:
    Type: AWS::ElasticLoadBalancingV2::ListenerRule
    Properties:
      Priority: !GetAtt AllocateAlbRulePriorityCustomResource.Priority
      [...]
  • Another use case is to set that priority as a CfnParameter, but when we call getValueAsNumber() it will generate a random number probably out of the allowed ranges.

Proposed solution

  • Add a new priority setter accepting Reference as argument.
  • or/and Remove the check on priorityValue.

I vote for option 1.


This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
AlJohricommented, Nov 14, 2020

Thank you for sharing @garrettux! That worked for me as well. Here’s my solution with the lambda code as well: https://gist.github.com/AlJohri/fa18bf58b338888934a140c8b6214fdd

Would love any comments if there’s a cleaner way to go about things.

1reaction
garrettuxcommented, Nov 6, 2020

FWIW I was having the same issue and was able to work around it with an escape hatch:

        const nextListenerRulePriorityLambda = new CustomResource(this, 'nextListenerRulePriority', {
            resourceType: 'Custom::AllocateAlbRulePriority',
            serviceToken: `arn:aws:lambda:${region}:${account}:function:AllocateAlbRulePriority`,
            properties:{
                ListenerArn: listenerArn
            }
        });

        const nextListenerRulePriority = nextListenerRulePriorityLambda.getAttString('Priority');
		
        const albPredeployListenerRule = new ApplicationListenerRule(this, 'albPredeployListenerRule', {
            priority: 9999,
            listener: this.listener
        });
		
        // https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts#L231-L236
        const albRuleEscapeHatch = albPredeployListenerRule.node.defaultChild as CfnListenerRule;
        albRuleEscapeHatch.priority = Token.asNumber(nextListenerRulePriority);
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-elasticloadbalancingv2 module
If both are specified, both conditions must be met for the requests to be routed to the given target. priority is a required...
Read more >
@aws-cdk/aws-elasticloadbalancingv2 - Package Manager
Fast, reliable, and secure dependency management.
Read more >
ElasticLoadBalancingv2 — Boto3 Docs 1.26.36 documentation
This reference covers the following load balancer types: Application Load Balancer - Operates at the application layer (layer 7) and supports HTTP and...
Read more >
Error ListenerRule with identifier Priority 10 is currently in use ...
I figured out I could use 4 when I attempted to create an ECS service on the AWS web console, attached to the...
Read more >
Find the first available priority number in an ELB ListenerRule ...
AWS::ElasticLoadBalancingV2::ListenerRule requires a priority. We're using specific, targeted hostname rules, so priority doesn't matter, ...
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