Skip to content

create_automation_rule

create_automation_rule(
    name: RuleName,
    rule_type: RuleType,
    recommended_action_types: RecommendedActionTypeList,
    schedule: Schedule,
    status: RuleStatus,
    *,
    config_overrides: Optional[ComputeOptimizerAutomationClientConfig] = None,
    description: Optional[RuleDescription] = None,
    organization_configuration: Optional[OrganizationConfiguration] = None,
    priority: Optional[str] = None,
    criteria: Optional[Criteria] = None,
    tags: Optional[TagList] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateAutomationRuleResponse

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

Parameters:

  • name (RuleName) –

    The name of the automation rule.

  • description (Optional[RuleDescription], default: None ) –

    A description of the automation rule.

  • rule_type (RuleType) –

    The type of rule.

    Only the management account or a delegated administrator can set the ruleType to be OrganizationRule.

  • organization_configuration (Optional[OrganizationConfiguration], default: None ) –

    Configuration for organization-level rules. Required for OrganizationRule type.

  • priority (Optional[str], default: None ) –

    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.

  • recommended_action_types (RecommendedActionTypeList) –

    The types of recommended actions this rule will automate.

  • criteria (Optional[Criteria], default: None ) –

    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.

  • schedule (Schedule) –

    The schedule for when the rule should run.

  • status (RuleStatus) –

    The status of the rule

  • tags (Optional[TagList], default: None ) –

    The tags to associate with the rule.

  • client_token (Optional[ClientToken], default: None ) –

    A unique identifier to ensure idempotency of the request.

Raises:

Source code in docs_src/capo_compute_optimizer_automation/_services/compute_optimizer_automation.py
def create_automation_rule(
    self,
    name: "capo_compute_optimizer_automation.types.rule_name.RuleName",
    rule_type: "capo_compute_optimizer_automation.types.rule_type.RuleType",
    recommended_action_types: "capo_compute_optimizer_automation.types.recommended_action_type_list.RecommendedActionTypeList",
    schedule: "capo_compute_optimizer_automation.types.schedule.Schedule",
    status: "capo_compute_optimizer_automation.types.rule_status.RuleStatus",
    *,
    config_overrides: Optional[ComputeOptimizerAutomationClientConfig] = None,
    description: Optional[
        "capo_compute_optimizer_automation.types.rule_description.RuleDescription"
    ] = None,
    organization_configuration: Optional[
        "capo_compute_optimizer_automation.types.organization_configuration.OrganizationConfiguration"
    ] = None,
    priority: Optional[str] = None,
    criteria: Optional[
        "capo_compute_optimizer_automation.types.criteria.Criteria"
    ] = None,
    tags: Optional[
        "capo_compute_optimizer_automation.types.tag_list.TagList"
    ] = None,
    client_token: Optional[
        "capo_compute_optimizer_automation.types.client_token.ClientToken"
    ] = None,
) -> "capo_compute_optimizer_automation.types.create_automation_rule_response.CreateAutomationRuleResponse":
    """<p> Creates a new automation rule to apply recommended actions to resources based on specified criteria. </p>

    Args:
        name: <p> The name of the automation rule. </p>
        description: <p> A description of the automation rule. </p>
        rule_type: <p> The type of rule. </p> <note> <p>Only the management account or a delegated administrator can set the ruleType to be OrganizationRule.</p> </note>
        organization_configuration: <p> Configuration for organization-level rules. Required for OrganizationRule type. </p>
        priority: <p>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. </p>
        recommended_action_types: <p> The types of recommended actions this rule will automate. </p>
        criteria: <p>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. </p>
        schedule: <p> The schedule for when the rule should run. </p>
        status: <p>The status of the rule </p>
        tags: <p> The tags to associate with the rule. </p>
        client_token: <p> A unique identifier to ensure idempotency of the request. </p>

    Raises:
        capo_compute_optimizer_automation.errors.access_denied_exception.AccessDeniedException: <p> You do not have sufficient permissions to perform this action. </p>
        capo_compute_optimizer_automation.errors.forbidden_exception.ForbiddenException: <p> You are not authorized to perform this action. </p>
        capo_compute_optimizer_automation.errors.idempotency_token_in_use_exception.IdempotencyTokenInUseException: <p> The specified client token is already in use. </p>
        capo_compute_optimizer_automation.errors.idempotent_parameter_mismatch_exception.IdempotentParameterMismatchException: <p>Exception thrown when the same client token is used with different parameters, indicating a mismatch in idempotent request parameters.</p>
        capo_compute_optimizer_automation.errors.internal_server_exception.InternalServerException: <p> An internal error occurred while processing the request. </p>
        capo_compute_optimizer_automation.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p> One or more parameter values are not valid. </p>
        capo_compute_optimizer_automation.errors.opt_in_required_exception.OptInRequiredException: <p> The account must be opted in to Compute Optimizer Automation before performing this action. </p>
        capo_compute_optimizer_automation.errors.resource_not_found_exception.ResourceNotFoundException: <p> The specified resource was not found. </p>
        capo_compute_optimizer_automation.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p> The request would exceed service quotas. </p>
        capo_compute_optimizer_automation.errors.service_unavailable_exception.ServiceUnavailableException: <p> The service is temporarily unavailable. </p>
        capo_compute_optimizer_automation.errors.throttling_exception.ThrottlingException: <p> The request was denied due to request throttling. </p>
        capo_compute_optimizer_automation.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_compute_optimizer_automation.types.create_automation_rule_request.CreateAutomationRuleRequest]",
    ) -> OperationResponse[
        "capo_compute_optimizer_automation.types.create_automation_rule_response.CreateAutomationRuleResponse"
    ]:
        import capo_compute_optimizer_automation._operations.compute_optimizer_automation_service.create_automation_rule

        output, http_response = (
            capo_compute_optimizer_automation._operations.compute_optimizer_automation_service.create_automation_rule.create_automation_rule(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateAutomationRule")
    )
    input_: capo_compute_optimizer_automation.types.create_automation_rule_request.CreateAutomationRuleRequest = {
        "name": name,
        "rule_type": rule_type,
        "recommended_action_types": recommended_action_types,
        "schedule": schedule,
        "status": status,
    }
    if description is not None:
        input_["description"] = description
    if organization_configuration is not None:
        input_["organization_configuration"] = organization_configuration
    if priority is not None:
        input_["priority"] = priority
    if criteria is not None:
        input_["criteria"] = criteria
    if tags is not None:
        input_["tags"] = tags
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output