Skip to content

create_custom_metric

create_custom_metric(
    metric_name: MetricName,
    metric_type: CustomMetricType,
    client_request_token: ClientRequestToken,
    *,
    config_overrides: Optional[IoTClientConfig] = None,
    display_name: Optional[CustomMetricDisplayName] = None,
    tags: Optional[TagList] = None,
) -> CreateCustomMetricResponse

The IoT Device Defender detect feature will no longer be available to new customers starting August 31, 2026. If you would like to use the detect feature, sign up prior to August 31, 2026. To learn about alternatives to IoT Device Defender detect, see IoT Device Defender detect feature availability change in the IoT Device Defender Developer Guide. There is no change to IoT Device Defender audit availability.

Use this API to define a Custom Metric published by your devices to Device Defender.

Requires permission to access the CreateCustomMetric action.

Parameters:

  • metric_name (MetricName) –

    The name of the custom metric. This will be used in the metric report submitted from the device/thing. The name can't begin with aws:. You can't change the name after you define it.

  • display_name (Optional[CustomMetricDisplayName], default: None ) –

    The friendly name in the console for the custom metric. This name doesn't have to be unique. Don't use this name as the metric identifier in the device metric report. You can update the friendly name after you define it.

  • metric_type (CustomMetricType) –

    The type of the custom metric.

    The type number only takes a single metric value as an input, but when you submit the metrics value in the DeviceMetrics report, you must pass it as an array with a single value.

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

    Metadata that can be used to manage the custom metric.

  • client_request_token (ClientRequestToken) –

    Each custom metric must have a unique client request token. If you try to create a new custom metric that already exists with a different token, an exception occurs. If you omit this value, Amazon Web Services SDKs will automatically generate a unique client request.

Raises:

Source code in docs_src/capo_iot/_services/io_t.py
def create_custom_metric(
    self,
    metric_name: "capo_iot.types.metric_name.MetricName",
    metric_type: "capo_iot.types.custom_metric_type.CustomMetricType",
    client_request_token: "capo_iot.types.client_request_token.ClientRequestToken",
    *,
    config_overrides: Optional[IoTClientConfig] = None,
    display_name: Optional[
        "capo_iot.types.custom_metric_display_name.CustomMetricDisplayName"
    ] = None,
    tags: Optional["capo_iot.types.tag_list.TagList"] = None,
) -> "capo_iot.types.create_custom_metric_response.CreateCustomMetricResponse":
    """<note> <p>The IoT Device Defender detect feature will no longer be available to new customers starting August 31, 2026. If you would like to use the detect feature, sign up prior to August 31, 2026. To learn about alternatives to IoT Device Defender detect, see IoT Device Defender detect feature availability change in the IoT Device Defender Developer Guide. There is no change to IoT Device Defender audit availability.</p> </note> <p> Use this API to define a Custom Metric published by your devices to Device Defender. </p> <p>Requires permission to access the <a href="https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsiot.html#awsiot-actions-as-permissions">CreateCustomMetric</a> action.</p>

    Args:
        metric_name: <p> The name of the custom metric. This will be used in the metric report submitted from the device/thing. The name can't begin with <code>aws:</code>. You can't change the name after you define it.</p>
        display_name: <p> The friendly name in the console for the custom metric. This name doesn't have to be unique. Don't use this name as the metric identifier in the device metric report. You can update the friendly name after you define it.</p>
        metric_type: <p> The type of the custom metric. </p> <important> <p>The type <code>number</code> only takes a single metric value as an input, but when you submit the metrics value in the DeviceMetrics report, you must pass it as an array with a single value.</p> </important>
        tags: <p> Metadata that can be used to manage the custom metric. </p>
        client_request_token: <p>Each custom metric must have a unique client request token. If you try to create a new custom metric that already exists with a different token, an exception occurs. If you omit this value, Amazon Web Services SDKs will automatically generate a unique client request. </p>

    Raises:
        capo_iot.errors.internal_failure_exception.InternalFailureException: <p>An unexpected error has occurred.</p>
        capo_iot.errors.invalid_request_exception.InvalidRequestException: <p>The request is not valid.</p>
        capo_iot.errors.limit_exceeded_exception.LimitExceededException: <p>A limit has been exceeded.</p>
        capo_iot.errors.resource_already_exists_exception.ResourceAlreadyExistsException: <p>The resource already exists.</p>
        capo_iot.errors.throttling_exception.ThrottlingException: <p>The rate exceeds the limit.</p>
        capo_iot.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_iot.types.create_custom_metric_request.CreateCustomMetricRequest]",
    ) -> OperationResponse[
        "capo_iot.types.create_custom_metric_response.CreateCustomMetricResponse"
    ]:
        import capo_iot._operations.aws_iot_service.create_custom_metric

        output, http_response = (
            capo_iot._operations.aws_iot_service.create_custom_metric.create_custom_metric(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateCustomMetric")
    )
    input_: capo_iot.types.create_custom_metric_request.CreateCustomMetricRequest = {
        "metric_name": metric_name,
        "metric_type": metric_type,
        "client_request_token": client_request_token,
    }
    if display_name is not None:
        input_["display_name"] = display_name
    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