create_rule
¶
create_rule(
*,
config_overrides: Optional[ElasticLoadBalancingv2ClientConfig] = None,
listener_arn: Optional[ListenerArn] = None,
conditions: Optional[RuleConditionList] = None,
priority: Optional[RulePriority] = None,
actions: Optional[Actions] = None,
tags: Optional[TagList] = None,
transforms: Optional[RuleTransformList] = None,
) -> CreateRuleOutput
Creates a rule for the specified listener. The listener must be associated with an Application Load Balancer or a dual-stack Network Load Balancer.
Each rule consists of a priority, one or more actions, and one or more conditions. Rules are evaluated in priority order, from the lowest value to the highest value. When the conditions for a rule are met, its actions are performed. If the conditions for no rules are met, the actions for the default rule are performed. For more information, see Listener rules in the Application Load Balancers Guide or Listener rules in the Network Load Balancers Guide.
Parameters:
-
listener_arn(Optional[ListenerArn], default:None) –The Amazon Resource Name (ARN) of the listener.
-
conditions(Optional[RuleConditionList], default:None) –The conditions.
-
priority(Optional[RulePriority], default:None) –The rule priority. A listener can't have multiple rules with the same priority.
-
actions(Optional[Actions], default:None) –The actions.
-
tags(Optional[TagList], default:None) –The tags to assign to the rule.
-
transforms(Optional[RuleTransformList], default:None) –The transforms to apply to requests that match this rule. You can add one host header rewrite transform and one URL rewrite transform.
Raises:
-
IncompatibleProtocolsException–The specified configuration is not valid with this protocol.
-
InvalidConfigurationRequestException–The requested configuration is not valid.
-
InvalidLoadBalancerActionException–The requested action is not valid.
-
ListenerNotFoundException–The specified listener does not exist.
-
PriorityInUseException–The specified priority is in use.
-
TargetGroupAssociationLimitException–You've reached the limit on the number of load balancers per target group.
-
TargetGroupNotFoundException–The specified target group does not exist.
-
TooManyActionsException–You've reached the limit on the number of actions per rule.
-
TooManyRegistrationsForTargetIdException–You've reached the limit on the number of times a target can be registered with a load balancer.
-
TooManyRulesException–You've reached the limit on the number of rules per load balancer.
-
TooManyTagsException–You've reached the limit on the number of tags for this resource.
-
TooManyTargetGroupsException–You've reached the limit on the number of target groups for your Amazon Web Services account.
-
TooManyTargetsException–You've reached the limit on the number of targets.
-
TooManyUniqueTargetGroupsPerLoadBalancerException–You've reached the limit on the number of unique target groups per load balancer across all listeners. If a target group is used by multiple actions for a load balancer, it is counted as only one use.
-
UnsupportedProtocolException–The specified protocol is not supported.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
To create a rule This example creates a rule that forwards requests to the specified target group if the URL contains the specified pattern (for example, /img/*).
>>> client.create_rule(listener_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2', conditions=[{'Field': 'path-pattern', 'Values': ['/img/*']}], priority=10, actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067'}])
To create a listener rule that routes IPv4 traffic on a Network Load Balancer
This example creates a rule on a dual-stack Network Load Balancer that routes IPv4 source traffic to an IPv4 target group.
>>> client.create_rule(listener_arn='arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/net/my-nlb/1234567890abcdef/1234567890abcdef', conditions=[{'Field': 'source-ip', 'SourceIpConfig': {'IpAddressType': 'ipv4'}}], priority=10, actions=[{'Type': 'forward', 'TargetGroupArn': 'arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-ipv4-targets/1234567890abcdef'}])
Source code in docs_src/capo_elastic_load_balancing_v2/_services/elastic_load_balancingv2.py
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 | |