Add a listener rule
You configure a listener rule with a priority, conditions, and actions. A rule routes traffic to the specified target groups when the rule conditions are met. For more information about rule concepts, see Listener rules.
- Console
-
To create a listener rule
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
. -
In the navigation pane, choose Load Balancers.
-
Choose the name of the load balancer to open its detail page.
-
On the Listeners and rules tab, choose the text in the Protocol:Port column to open the detail page for the listener.
-
On the Rules tab, choose Add rule.
-
For Name, optionally enter a name for the rule.
-
For Condition, the source IP condition is selected. For IP address type, choose IPv4 or IPv6.
-
For Action, choose Forward to target groups, and then choose one or more target groups. If you choose more than one target group, you must specify a weight for each target group.
-
Choose Next.
-
For Priority, enter a value from 1-50,000. Rules are evaluated in priority order from the lowest value to the highest value.
-
Choose Next.
-
On the Review and create page, choose Create.
- AWS CLI
-
To create a listener rule that routes IPv4 traffic
Use the following create-rule command to create a rule that routes IPv4 source traffic to an IPv4 target group.
aws elbv2 create-rule \ --listener-arnlistener-arn\ --priority10\ --conditions '[{"Field":"source-ip","SourceIpConfig":{"IpAddressType":"ipv4"}}]' \ --actions '[{"Type":"forward","TargetGroupArn":"ipv4-target-group-arn"}]'To create a listener rule that routes IPv6 traffic
Use the following create-rule command to create a rule that routes IPv6 source traffic to an IPv6 target group.
aws elbv2 create-rule \ --listener-arnlistener-arn\ --priority20\ --conditions '[{"Field":"source-ip","SourceIpConfig":{"IpAddressType":"ipv6"}}]' \ --actions '[{"Type":"forward","TargetGroupArn":"ipv6-target-group-arn"}]'To create a listener rule with weighted target groups
Use the following create-rule command to create a rule that routes traffic to multiple target groups with weights.
aws elbv2 create-rule \ --listener-arnlistener-arn\ --priority10\ --conditions '[{"Field":"source-ip","SourceIpConfig":{"IpAddressType":"ipv4"}}]' \ --actions '[{"Type":"forward","ForwardConfig":{"TargetGroups":[{"TargetGroupArn":"ipv4-tg-1-arn","Weight":70},{"TargetGroupArn":"ipv4-tg-2-arn","Weight":30}]}}]'