Skip to content

create_omni_slo

create_omni_slo(
    space_id: SpaceId,
    name: SloName,
    service_attributes: SloServiceAttributes,
    sli: Sli,
    objective: SloObjective,
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    description: Optional[SloDescription] = None,
    tags: Optional[TagMap] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateOmniSloOutput

Creates a service level objective (SLO) within a space. The SLO measures a service against a reliability target over a time window.

Parameters:

  • space_id (SpaceId) –

    The unique ID of the space to create the SLO in.

  • name (SloName) –

    The display name of the SLO. Not unique within a space; the sloId returned in the response identifies the SLO.

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

    An optional description of the SLO.

  • service_attributes (SloServiceAttributes) –

    The service the SLO is about. Descriptive only: it is not checked against the SLI and never used for authorization.

  • sli (Sli) –

    What the SLO measures.

  • objective (SloObjective) –

    The reliability target, the warning threshold and the window the target is measured over.

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

    The tags to associate with the SLO.

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

    Idempotency token for safe retries. Retrying with the same token returns the original SLO instead of creating a duplicate.

Raises:

Examples:

Create a request-based SLO The following example creates an SLO that 99.9 percent of checkout API requests succeed over a rolling 30 days, and enters the WARNING state once 75 percent of the error budget is consumed. The good and total queries count events over the range the service substitutes for $__interval. The client token makes a retry return this SLO instead of creating a second one. A new SLO has not been evaluated yet, so the response has no state. Payloads are shown as JSON; on the wire they are CBOR-encoded.

>>> client.create_omni_slo(space_id='a1b2c3d4-5e6f-4a3b-8c9d-0e1f2a3b4c5d', name='checkout-api-availability', description='99.9 percent of checkout API requests succeed over a rolling 30 days.', service_attributes={'serviceName': 'checkout-api', 'serviceNamespace': 'retail', 'cloudProvider': 'aws', 'cloudAccountId': '123456789012', 'cloudRegion': 'us-east-1', 'deploymentEnvironmentName': 'prod'}, sli={'events': {'good': {'language': 'PROMQL', 'expression': 'sum(increase({"http.server.request.duration_count", "service.name"="checkout-api", "http.response.status_code"!~"5.."}[$__interval]))'}, 'total': {'language': 'PROMQL', 'expression': 'sum(increase({"http.server.request.duration_count", "service.name"="checkout-api"}[$__interval]))'}}}, objective={'target': 99.9, 'warningBudgetConsumedRatio': 0.75, 'timeWindow': {'rolling': {'days': 30}}}, tags={'team': 'payments'}, client_token='3f1c9a2e-7b4d-4e8a-9c6f-1d2e3f4a5b6c')
Create a time-slice SLO over a calendar week
The following example creates an SLO that judges each 1-minute period good when its p99 latency is at most 300 milliseconds, with a target of 99.9 percent of periods in each calendar week, starting on Monday in the America/New_York time zone. The error budget is counted in periods and restarts at each week boundary. No warning ratio is set, so the SLO is never in the WARNING state. A new SLO has not been evaluated yet, so the response has no state. Payloads are shown as JSON; on the wire they are CBOR-encoded.
>>> client.create_omni_slo(space_id='a1b2c3d4-5e6f-4a3b-8c9d-0e1f2a3b4c5d', name='checkout-api-latency-p99', service_attributes={'serviceName': 'checkout-api', 'deploymentEnvironmentName': 'prod'}, sli={'periods': {'periodMinutes': 1, 'query': {'language': 'PROMQL', 'expression': 'histogram_quantile(0.99, sum by (le) (rate({"http.server.request.duration_bucket", "service.name"="checkout-api"}[$__interval])))'}, 'good': {'comparator': 'LTE', 'threshold': 0.3}}}, objective={'target': 99.9, 'timeWindow': {'calendar': {'unit': 'WEEK', 'weekStartDay': 'MONDAY', 'timeZone': 'America/New_York'}}})
Source code in docs_src/capo_cloudwatchomni/_services/cloud_watch_omni.py
def create_omni_slo(
    self,
    space_id: "capo_cloudwatchomni.types.space_id.SpaceId",
    name: "capo_cloudwatchomni.types.slo_name.SloName",
    service_attributes: "capo_cloudwatchomni.types.slo_service_attributes.SloServiceAttributes",
    sli: "capo_cloudwatchomni.types.sli.Sli",
    objective: "capo_cloudwatchomni.types.slo_objective.SloObjective",
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    description: Optional[
        "capo_cloudwatchomni.types.slo_description.SloDescription"
    ] = None,
    tags: Optional["capo_cloudwatchomni.types.tag_map.TagMap"] = None,
    client_token: Optional[
        "capo_cloudwatchomni.types.client_token.ClientToken"
    ] = None,
) -> "capo_cloudwatchomni.types.create_omni_slo_output.CreateOmniSloOutput":
    """Creates a service level objective (SLO) within a space. The SLO measures a service against a reliability target over a time window.

    Args:
        space_id: The unique ID of the space to create the SLO in.
        name: The display name of the SLO. Not unique within a space; the sloId returned in the response identifies the SLO.
        description: An optional description of the SLO.
        service_attributes: The service the SLO is about. Descriptive only: it is not checked against the SLI and never used for authorization.
        sli: What the SLO measures.
        objective: The reliability target, the warning threshold and the window the target is measured over.
        tags: The tags to associate with the SLO.
        client_token: Idempotency token for safe retries. Retrying with the same token returns the original SLO instead of creating a duplicate.

    Raises:
        capo_cloudwatchomni.errors.access_denied_exception.AccessDeniedException: The caller is not authorized to perform this action.
        capo_cloudwatchomni.errors.conflict_exception.ConflictException: The operation could not be completed because of a conflict with the current state of the resource.
        capo_cloudwatchomni.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_cloudwatchomni.errors.resource_not_found_exception.ResourceNotFoundException: The specified resource does not exist.
        capo_cloudwatchomni.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: A service quota was exceeded.
        capo_cloudwatchomni.errors.throttling_exception.ThrottlingException: The request was throttled due to exceeding the allowed request rate.
        capo_cloudwatchomni.errors.validation_exception.ValidationException: A parameter is specified incorrectly.
        capo_cloudwatchomni.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Create a request-based SLO
        The following example creates an SLO that 99.9 percent of checkout API requests succeed over a rolling 30 days, and enters the WARNING state once 75 percent of the error budget is consumed. The good and total queries count events over the range the service substitutes for $__interval. The client token makes a retry return this SLO instead of creating a second one. A new SLO has not been evaluated yet, so the response has no state. Payloads are shown as JSON; on the wire they are CBOR-encoded.

        >>> client.create_omni_slo(space_id='a1b2c3d4-5e6f-4a3b-8c9d-0e1f2a3b4c5d', name='checkout-api-availability', description='99.9 percent of checkout API requests succeed over a rolling 30 days.', service_attributes={'serviceName': 'checkout-api', 'serviceNamespace': 'retail', 'cloudProvider': 'aws', 'cloudAccountId': '123456789012', 'cloudRegion': 'us-east-1', 'deploymentEnvironmentName': 'prod'}, sli={'events': {'good': {'language': 'PROMQL', 'expression': 'sum(increase({"http.server.request.duration_count", "service.name"="checkout-api", "http.response.status_code"!~"5.."}[$__interval]))'}, 'total': {'language': 'PROMQL', 'expression': 'sum(increase({"http.server.request.duration_count", "service.name"="checkout-api"}[$__interval]))'}}}, objective={'target': 99.9, 'warningBudgetConsumedRatio': 0.75, 'timeWindow': {'rolling': {'days': 30}}}, tags={'team': 'payments'}, client_token='3f1c9a2e-7b4d-4e8a-9c6f-1d2e3f4a5b6c')
        Create a time-slice SLO over a calendar week
        The following example creates an SLO that judges each 1-minute period good when its p99 latency is at most 300 milliseconds, with a target of 99.9 percent of periods in each calendar week, starting on Monday in the America/New_York time zone. The error budget is counted in periods and restarts at each week boundary. No warning ratio is set, so the SLO is never in the WARNING state. A new SLO has not been evaluated yet, so the response has no state. Payloads are shown as JSON; on the wire they are CBOR-encoded.

        >>> client.create_omni_slo(space_id='a1b2c3d4-5e6f-4a3b-8c9d-0e1f2a3b4c5d', name='checkout-api-latency-p99', service_attributes={'serviceName': 'checkout-api', 'deploymentEnvironmentName': 'prod'}, sli={'periods': {'periodMinutes': 1, 'query': {'language': 'PROMQL', 'expression': 'histogram_quantile(0.99, sum by (le) (rate({"http.server.request.duration_bucket", "service.name"="checkout-api"}[$__interval])))'}, 'good': {'comparator': 'LTE', 'threshold': 0.3}}}, objective={'target': 99.9, 'timeWindow': {'calendar': {'unit': 'WEEK', 'weekStartDay': 'MONDAY', 'timeZone': 'America/New_York'}}})
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatchomni.types.create_omni_slo_input.CreateOmniSloInput]",
    ) -> OperationResponse[
        "capo_cloudwatchomni.types.create_omni_slo_output.CreateOmniSloOutput"
    ]:
        import capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_omni_slo

        output, http_response = (
            capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_omni_slo.create_omni_slo(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateOmniSlo")
    )
    input_: capo_cloudwatchomni.types.create_omni_slo_input.CreateOmniSloInput = {
        "space_id": space_id,
        "name": name,
        "service_attributes": service_attributes,
        "sli": sli,
        "objective": objective,
    }
    if description is not None:
        input_["description"] = description
    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