createAutomationRule method

Future<CreateAutomationRuleResponse> createAutomationRule({
  1. required String name,
  2. required List<RecommendedActionType> recommendedActionTypes,
  3. required RuleType ruleType,
  4. required Schedule schedule,
  5. required RuleStatus status,
  6. String? clientToken,
  7. Criteria? criteria,
  8. String? description,
  9. OrganizationConfiguration? organizationConfiguration,
  10. String? priority,
  11. List<Tag>? tags,
})

Creates a new automation rule to apply recommended actions to resources based on specified criteria.

May throw AccessDeniedException. May throw ForbiddenException. May throw IdempotencyTokenInUseException. May throw IdempotentParameterMismatchException. May throw InternalServerException. May throw InvalidParameterValueException. May throw OptInRequiredException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ServiceUnavailableException. May throw ThrottlingException.

Parameter name : The name of the automation rule.

Parameter recommendedActionTypes : The types of recommended actions this rule will automate.

Parameter ruleType : The type of rule.

Parameter schedule : The schedule for when the rule should run.

Parameter status : The status of the rule

Parameter clientToken : A unique identifier to ensure idempotency of the request.

Parameter criteria : A set of conditions that specify which recommended action qualify for implementation. When a rule is active and a recommended action matches these criteria, Compute Optimizer implements the action at the scheduled run time.

Parameter description : A description of the automation rule.

Parameter organizationConfiguration : Configuration for organization-level rules. Required for OrganizationRule type.

Parameter priority : A string representation of a decimal number between 0 and 1 (having up to 30 digits after the decimal point) that determines the priority of the rule. When multiple rules match the same recommended action, Compute Optimizer assigns the action to the rule with the lowest priority value (highest priority), even if that rule is scheduled to run later than other matching rules.

Parameter tags : The tags to associate with the rule.

Implementation

Future<CreateAutomationRuleResponse> createAutomationRule({
  required String name,
  required List<RecommendedActionType> recommendedActionTypes,
  required RuleType ruleType,
  required Schedule schedule,
  required RuleStatus status,
  String? clientToken,
  Criteria? criteria,
  String? description,
  OrganizationConfiguration? organizationConfiguration,
  String? priority,
  List<Tag>? tags,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'ComputeOptimizerAutomationService.CreateAutomationRule'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'name': name,
      'recommendedActionTypes':
          recommendedActionTypes.map((e) => e.value).toList(),
      'ruleType': ruleType.value,
      'schedule': schedule,
      'status': status.value,
      'clientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (criteria != null) 'criteria': criteria,
      if (description != null) 'description': description,
      if (organizationConfiguration != null)
        'organizationConfiguration': organizationConfiguration,
      if (priority != null) 'priority': priority,
      if (tags != null) 'tags': tags,
    },
  );

  return CreateAutomationRuleResponse.fromJson(jsonResponse.body);
}