I'm writing a script that will insert a new elbv2 listener rule on top of the listener rules already in the alb.
response = elbv2_client.create_rule(
ListenerArn=listener_arn,
Priority=1,
Conditions=[
{
'Field': 'http-request-method',
'HttpRequestMethodConfig': {
'Values': ['GET']
}
}
],
Actions=[
{
'Type': 'fixed-response',
'FixedResponseConfig':
{
'ContentType': 'text/html',
'MessageBody': html_object,
'StatusCode': '504'
}
}
]
)
Just as you would do on the AWS console when you insert a new rule on top and the rules automatically renumber themselves.
Problem is the rule['Priority'] number is not the same as the one being shown in the AWS console (as stated in the note here: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-update-rules.html)
Note: The console displays a relative sequence number for each rule, not the rule priority. You can get the priority of a rule by describing it using the AWS CLI or the Elastic Load Balancing API.
And when I use elbv2 create_rule(), it gives me this error if the top most rule is set to Priority = 1.
botocore.errorfactory.PriorityInUseException: An error occurred (PriorityInUse) when calling the CreateRule operation: Priority '1' is currently in use
TIA!