Skip to content

create_metric

create_metric(
    app_id: AppId,
    name: MetricDisplayName,
    description: MetricDescription,
    event_type: SourceEventType,
    unit_name: UnitName,
    definition: MetricDefinition,
    *,
    config_overrides: Optional[AppMonetizationClientConfig] = None,
    client_token: Optional[ClientToken] = None,
    tags: Optional[TagMap] = None,
) -> CreateMetricResponse

Creates a usage metric definition for an app. A metric beyond the Metrics per app quota is refused with ServiceQuotaExceededException.

Parameters:

  • app_id (AppId) –

    The ID of the app the metric belongs to.

  • name (MetricDisplayName) –

    A human-readable display name for the metric (for example, Riddles Solved).

  • description (MetricDescription) –

    A description of what the metric measures.

  • event_type (SourceEventType) –

    The event type this metric aggregates. Must match the eventType sent on PutEvent.

  • unit_name (UnitName) –

    The unit of measure for the metric (for example, "requests" or "tokens").

  • definition (MetricDefinition) –

    The aggregation definition: filters, aggregation function, grouping, and period.

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

    A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, the service ignores the request but does not return an error.

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

    Optional tags to add to the metric when it is created. Tagging on create also requires permission for appmonetization:TagResource.

Raises:

Source code in docs_src/capo_appmonetization/_services/app_monetization.py
def create_metric(
    self,
    app_id: "capo_appmonetization.types.app_id.AppId",
    name: "capo_appmonetization.types.metric_display_name.MetricDisplayName",
    description: "capo_appmonetization.types.metric_description.MetricDescription",
    event_type: "capo_appmonetization.types.source_event_type.SourceEventType",
    unit_name: "capo_appmonetization.types.unit_name.UnitName",
    definition: "capo_appmonetization.types.metric_definition.MetricDefinition",
    *,
    config_overrides: Optional[AppMonetizationClientConfig] = None,
    client_token: Optional[
        "capo_appmonetization.types.client_token.ClientToken"
    ] = None,
    tags: Optional["capo_appmonetization.types.tag_map.TagMap"] = None,
) -> "capo_appmonetization.types.create_metric_response.CreateMetricResponse":
    """Creates a usage metric definition for an app. A metric beyond the Metrics per app quota is refused with ServiceQuotaExceededException.

    Args:
        app_id: The ID of the app the metric belongs to.
        name: A human-readable display name for the metric (for example, `Riddles Solved`).
        description: A description of what the metric measures.
        event_type: The event type this metric aggregates. Must match the eventType sent on PutEvent.
        unit_name: The unit of measure for the metric (for example, "requests" or "tokens").
        definition: The aggregation definition: filters, aggregation function, grouping, and period.
        client_token: A unique, case-sensitive identifier to ensure that the operation completes no more than one time. If this token matches a previous request, the service ignores the request but does not return an error.
        tags: Optional tags to add to the metric when it is created. Tagging on create also requires permission for appmonetization:TagResource.

    Raises:
        capo_appmonetization.errors.access_denied_exception.AccessDeniedException: The caller does not have sufficient permission to perform this action.
        capo_appmonetization.errors.conflict_exception.ConflictException: The request conflicts with the current state of the resource, such as a duplicate identifier or a version mismatch. Retrieve the current state of the resource and retry the request.
        capo_appmonetization.errors.idempotency_conflict_exception.IdempotencyConflictException: The clientToken was reused with a request that differs from the original request. Retry the operation with a new clientToken.
        capo_appmonetization.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_appmonetization.errors.invalid_configuration_exception.InvalidConfigurationException: The requested configuration is not valid.
        capo_appmonetization.errors.resource_not_found_exception.ResourceNotFoundException: The referenced resource does not exist.
        capo_appmonetization.errors.revision_conflict_exception.RevisionConflictException: The request's revision does not match the resource's current revision. Retry with the current revision.
        capo_appmonetization.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: The request would cause a service quota to be exceeded.
        capo_appmonetization.errors.throttling_exception.ThrottlingException: The request was denied due to request throttling.
        capo_appmonetization.errors.validation_exception.ValidationException: The request failed input validation.
        capo_appmonetization.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

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

        output, http_response = (
            capo_appmonetization._operations.aws_monetization_ai_front_end.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_appmonetization.types.create_metric_request.CreateMetricRequest = {
        "app_id": app_id,
        "name": name,
        "description": description,
        "event_type": event_type,
        "unit_name": unit_name,
        "definition": definition,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    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