Skip to content

create_metric

create_metric(
    instance_id: InstanceId,
    name: MetricName,
    metric_calculation: MetricCalculation,
    unit: MetricUnit,
    *,
    config_overrides: Optional[ConnectClientConfig] = None,
    status: Optional[MetricStatus] = None,
    client_token: Optional[ClientToken] = None,
    description: Optional[MetricDescription] = None,
    positive_trend_indicator: Optional[TrendIndicator] = None,
    tags: Optional[TagMap] = None,
) -> CreateMetricResponse

Creates a new metric definition for the specified Connect Customer instance. You can create custom metrics that use formulas referencing existing Amazon Web Services-managed metrics, optionally with filters applied.

Parameters:

  • instance_id (InstanceId) –

    The identifier of the Connect Customer instance. You can find the instance ID in the Amazon Resource Name (ARN) of the instance.

  • name (MetricName) –

    The name of the metric.

  • metric_calculation (MetricCalculation) –

    The calculation definition for the metric, including the formula expression and the component metrics it references.

  • unit (MetricUnit) –

    The display unit for the metric's data.

  • status (Optional[MetricStatus], default: None ) –

    The publish status of the metric. Set to PUBLISHED to make the metric available for use in dashboards and reports, or SAVED to keep it in draft state.

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

    A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If not provided, the Amazon Web Services SDK populates this field. For more information about idempotency, see Making retries safe with idempotent APIs.

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

    The description of the metric.

  • positive_trend_indicator (Optional[TrendIndicator], default: None ) –

    How an increase in the metric value should be interpreted. Valid values: POSITIVE, NEUTRAL, NEGATIVE.

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

    The tags used to organize, track, or control access for this resource. For example, { "Tags": {"key1":"value1", "key2":"value2"} }.

Raises:

Source code in docs_src/capo_connect/_services/connect.py
def create_metric(
    self,
    instance_id: "capo_connect.types.instance_id.InstanceId",
    name: "capo_connect.types.metric_name.MetricName",
    metric_calculation: "capo_connect.types.metric_calculation.MetricCalculation",
    unit: "capo_connect.types.metric_unit.MetricUnit",
    *,
    config_overrides: Optional[ConnectClientConfig] = None,
    status: Optional["capo_connect.types.metric_status.MetricStatus"] = None,
    client_token: Optional["capo_connect.types.client_token.ClientToken"] = None,
    description: Optional[
        "capo_connect.types.metric_description.MetricDescription"
    ] = None,
    positive_trend_indicator: Optional[
        "capo_connect.types.trend_indicator.TrendIndicator"
    ] = None,
    tags: Optional["capo_connect.types.tag_map.TagMap"] = None,
) -> "capo_connect.types.create_metric_response.CreateMetricResponse":
    """<p>Creates a new metric definition for the specified Connect Customer instance. You can create custom metrics that use formulas referencing existing Amazon Web Services-managed metrics, optionally with filters applied.</p>

    Args:
        instance_id: <p>The identifier of the Connect Customer instance. You can <a href="https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html">find the instance ID</a> in the Amazon Resource Name (ARN) of the instance.</p>
        name: <p>The name of the metric.</p>
        metric_calculation: <p>The calculation definition for the metric, including the formula expression and the component metrics it references.</p>
        unit: <p>The display unit for the metric's data.</p>
        status: <p>The publish status of the metric. Set to <code>PUBLISHED</code> to make the metric available for use in dashboards and reports, or <code>SAVED</code> to keep it in draft state.</p>
        client_token: <p>A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If not provided, the Amazon Web Services SDK populates this field. For more information about idempotency, see <a href="https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/">Making retries safe with idempotent APIs</a>.</p>
        description: <p>The description of the metric.</p>
        positive_trend_indicator: <p>How an increase in the metric value should be interpreted. Valid values: <code>POSITIVE</code>, <code>NEUTRAL</code>, <code>NEGATIVE</code>.</p>
        tags: <p>The tags used to organize, track, or control access for this resource. For example, { "Tags": {"key1":"value1", "key2":"value2"} }.</p>

    Raises:
        capo_connect.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient permissions to perform this action.</p>
        capo_connect.errors.duplicate_resource_exception.DuplicateResourceException: <p>A resource with the specified name already exists.</p>
        capo_connect.errors.internal_service_exception.InternalServiceException: <p>Request processing failed because of an error or failure with the service.</p>
        capo_connect.errors.invalid_parameter_exception.InvalidParameterException: <p>One or more of the specified parameters are not valid.</p>
        capo_connect.errors.invalid_request_exception.InvalidRequestException: <p>The request is not valid.</p>
        capo_connect.errors.limit_exceeded_exception.LimitExceededException: <p>The allowed limit for the resource has been exceeded.</p>
        capo_connect.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource was not found.</p>
        capo_connect.errors.throttling_exception.ThrottlingException: <p>The throttling limit has been exceeded.</p>
        capo_connect.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_connect.types.create_metric_request.CreateMetricRequest]",
    ) -> OperationResponse[
        "capo_connect.types.create_metric_response.CreateMetricResponse"
    ]:
        import capo_connect._operations.amazon_connect_service.create_metric

        output, http_response = (
            capo_connect._operations.amazon_connect_service.create_metric.create_metric(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateMetric")
    )
    input_: capo_connect.types.create_metric_request.CreateMetricRequest = {
        "instance_id": instance_id,
        "name": name,
        "metric_calculation": metric_calculation,
        "unit": unit,
    }
    if status is not None:
        input_["status"] = status
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if description is not None:
        input_["description"] = description
    if positive_trend_indicator is not None:
        input_["positive_trend_indicator"] = positive_trend_indicator
    if tags is not None:
        input_["tags"] = tags

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