createRule method

Future<CreateRuleResult> createRule({
  1. required String detectorId,
  2. required String expression,
  3. required Language language,
  4. required List<String> outcomes,
  5. required String ruleId,
  6. String? description,
  7. List<Tag>? tags,
})

Creates a rule for use with the specified detector.

May throw ValidationException. May throw InternalServerException. May throw ThrottlingException. May throw AccessDeniedException.

Parameter detectorId : The detector ID for the rule's parent detector.

Parameter expression : The rule expression.

Parameter language : The language of the rule.

Parameter outcomes : The outcome or outcomes returned when the rule expression matches.

Parameter ruleId : The rule ID.

Parameter description : The rule description.

Parameter tags : A collection of key and value pairs.

Implementation

Future<CreateRuleResult> createRule({
  required String detectorId,
  required String expression,
  required Language language,
  required List<String> outcomes,
  required String ruleId,
  String? description,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(detectorId, 'detectorId');
  _s.validateStringLength(
    'detectorId',
    detectorId,
    1,
    64,
    isRequired: true,
  );
  ArgumentError.checkNotNull(expression, 'expression');
  _s.validateStringLength(
    'expression',
    expression,
    1,
    4096,
    isRequired: true,
  );
  ArgumentError.checkNotNull(language, 'language');
  ArgumentError.checkNotNull(outcomes, 'outcomes');
  ArgumentError.checkNotNull(ruleId, 'ruleId');
  _s.validateStringLength(
    'ruleId',
    ruleId,
    1,
    64,
    isRequired: true,
  );
  _s.validateStringLength(
    'description',
    description,
    1,
    128,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSHawksNestServiceFacade.CreateRule'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'detectorId': detectorId,
      'expression': expression,
      'language': language.toValue(),
      'outcomes': outcomes,
      'ruleId': ruleId,
      if (description != null) 'description': description,
      if (tags != null) 'tags': tags,
    },
  );

  return CreateRuleResult.fromJson(jsonResponse.body);
}