createRule
inline suspend fun ElasticLoadBalancingV2Client.createRule(crossinline block: CreateRuleRequest.Builder.() -> Unit): CreateRuleResponse
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.
Samples
// This example creates a rule that forwards requests to the specified target group if the URL contains
// the specified pattern (for example, /img/*).
val resp = elasticLoadBalancingV2Client.createRule {
listenerArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/app/my-load-balancer/50dc6c495c0c9188/f2f7dc8efc522ab2"
conditions = listOf<RuleCondition>(
RuleCondition {
field = "path-pattern"
values = listOf<String>(
"/img/*"
)
}
)
priority = 10
actions = listOf<Action>(
Action {
type = ActionTypeEnum.fromValue("forward")
targetGroupArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-targets/73e2d6bc24d8a067"
}
)
}Content copied to clipboard
// This example creates a rule on a dual stack Network Load Balancer that routes IPv4 source traffic to
// an IPv4 target group.
val resp = elasticLoadBalancingV2Client.createRule {
listenerArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:listener/net/my-nlb/1234567890abcdef/1234567890abcdef"
conditions = listOf<RuleCondition>(
RuleCondition {
field = "source-ip"
sourceIpConfig = SourceIpConditionConfig {
ipAddressType = SourceIpAddressTypeEnum.fromValue("ipv4")
}
}
)
priority = 10
actions = listOf<Action>(
Action {
type = ActionTypeEnum.fromValue("forward")
targetGroupArn = "arn:aws:elasticloadbalancing:us-west-2:123456789012:targetgroup/my-ipv4-targets/1234567890abcdef"
}
)
}Content copied to clipboard