createCustomMetric method

Future<CreateCustomMetricResponse> createCustomMetric({
  1. required String metricName,
  2. required CustomMetricType metricType,
  3. String? clientRequestToken,
  4. String? displayName,
  5. List<Tag>? tags,
})

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

May throw InvalidRequestException. May throw LimitExceededException. May throw ResourceAlreadyExistsException. May throw ThrottlingException. May throw InternalFailureException.

Parameter metricName : The name of the custom metric. This will be used in the metric report submitted from the device/thing. Shouldn't begin with aws:. Cannot be updated once defined.

Parameter metricType : The type of the custom metric. Types include string-list, ip-address-list, number-list, and number.

Parameter 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, AWS SDKs will automatically generate a unique client request.

Parameter displayName : Field represents a friendly name in the console for the custom metric; it doesn't have to be unique. Don't use this name as the metric identifier in the device metric report. Can be updated once defined.

Parameter tags : Metadata that can be used to manage the custom metric.

Implementation

Future<CreateCustomMetricResponse> createCustomMetric({
  required String metricName,
  required CustomMetricType metricType,
  String? clientRequestToken,
  String? displayName,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(metricName, 'metricName');
  _s.validateStringLength(
    'metricName',
    metricName,
    1,
    128,
    isRequired: true,
  );
  ArgumentError.checkNotNull(metricType, 'metricType');
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    1,
    64,
  );
  _s.validateStringLength(
    'displayName',
    displayName,
    0,
    128,
  );
  final $payload = <String, dynamic>{
    'metricType': metricType.toValue(),
    'clientRequestToken': clientRequestToken ?? _s.generateIdempotencyToken(),
    if (displayName != null) 'displayName': displayName,
    if (tags != null) 'tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/custom-metric/${Uri.encodeComponent(metricName)}',
    exceptionFnMap: _exceptionFns,
  );
  return CreateCustomMetricResponse.fromJson(response);
}