createRule method

Future<CreateRuleOutput> createRule({
  1. required List<Action> actions,
  2. required List<RuleCondition> conditions,
  3. required String listenerArn,
  4. required int priority,
  5. List<Tag>? tags,
  6. List<RuleTransform>? transforms,
})

Creates a rule for the specified listener. The listener must be associated with an Application Load Balancer.

Each rule consists of a priority, one or more actions, one or more conditions, and up to two optional transforms. 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.

May throw IncompatibleProtocolsException. May throw InvalidConfigurationRequestException. May throw InvalidLoadBalancerActionException. May throw ListenerNotFoundException. May throw PriorityInUseException. May throw TargetGroupAssociationLimitException. May throw TargetGroupNotFoundException. May throw TooManyActionsException. May throw TooManyRegistrationsForTargetIdException. May throw TooManyRulesException. May throw TooManyTagsException. May throw TooManyTargetGroupsException. May throw TooManyTargetsException. May throw TooManyUniqueTargetGroupsPerLoadBalancerException. May throw UnsupportedProtocolException.

Parameter actions : The actions.

Parameter conditions : The conditions.

Parameter listenerArn : The Amazon Resource Name (ARN) of the listener.

Parameter priority : The rule priority. A listener can't have multiple rules with the same priority.

Parameter tags : The tags to assign to the rule.

Parameter transforms : The transforms to apply to requests that match this rule. You can add one host header rewrite transform and one URL rewrite transform.

Implementation

Future<CreateRuleOutput> createRule({
  required List<Action> actions,
  required List<RuleCondition> conditions,
  required String listenerArn,
  required int priority,
  List<Tag>? tags,
  List<RuleTransform>? transforms,
}) async {
  _s.validateNumRange(
    'priority',
    priority,
    1,
    50000,
    isRequired: true,
  );
  final $request = <String, String>{
    if (actions.isEmpty)
      'Actions': ''
    else
      for (var i1 = 0; i1 < actions.length; i1++)
        for (var e3 in actions[i1].toQueryMap().entries)
          'Actions.member.${i1 + 1}.${e3.key}': e3.value,
    if (conditions.isEmpty)
      'Conditions': ''
    else
      for (var i1 = 0; i1 < conditions.length; i1++)
        for (var e3 in conditions[i1].toQueryMap().entries)
          'Conditions.member.${i1 + 1}.${e3.key}': e3.value,
    'ListenerArn': listenerArn,
    'Priority': priority.toString(),
    if (tags != null)
      if (tags.isEmpty)
        'Tags': ''
      else
        for (var i1 = 0; i1 < tags.length; i1++)
          for (var e3 in tags[i1].toQueryMap().entries)
            'Tags.member.${i1 + 1}.${e3.key}': e3.value,
    if (transforms != null)
      if (transforms.isEmpty)
        'Transforms': ''
      else
        for (var i1 = 0; i1 < transforms.length; i1++)
          for (var e3 in transforms[i1].toQueryMap().entries)
            'Transforms.member.${i1 + 1}.${e3.key}': e3.value,
  };
  final $result = await _protocol.send(
    $request,
    action: 'CreateRule',
    version: '2015-12-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    resultWrapper: 'CreateRuleResult',
  );
  return CreateRuleOutput.fromXml($result);
}