AppMonetization / Client / create_metric

create_metric

AppMonetization.Client.create_metric(**kwargs)

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

See also: AWS API Documentation

Request Syntax

response = client.create_metric(
    appId='string',
    name='string',
    description='string',
    eventType='string',
    unitName='string',
    definition={
        'filters': [
            {
                'field': 'string',
                'operator': 'EQUALS'|'NOT_EQUALS'|'IN'|'NOT_IN',
                'values': [
                    'string',
                ]
            },
        ],
        'function': 'SUM'|'COUNT'|'MAX',
        'functionField': 'string',
        'groupBy': [
            'string',
        ],
        'period': 'MONTHLY'
    },
    clientToken='string',
    tags={
        'string': 'string'
    }
)
Parameters:
  • appId (string) –

    [REQUIRED]

    The ID of the app the metric belongs to.

  • name (string) –

    [REQUIRED]

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

  • description (string) –

    [REQUIRED]

    A description of what the metric measures.

  • eventType (string) –

    [REQUIRED]

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

  • unitName (string) –

    [REQUIRED]

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

  • definition (dict) –

    [REQUIRED]

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

    • filters (list) – [REQUIRED]

      The predicates selecting which events contribute to the metric. Combined with logical AND.

      • (dict) –

        A single predicate that selects which events contribute to a metric.

        • field (string) – [REQUIRED]

          The event property key the filter is evaluated against.

        • operator (string) – [REQUIRED]

          The comparison operator (EQUALS, NOT_EQUALS, IN, or NOT_IN).

        • values (list) – [REQUIRED]

          The values the field is compared against.

          • (string) –

            A value the field is compared against, 1-256 characters. Single quotes (’) and backslashes () are not allowed.

    • function (string) – [REQUIRED]

      The aggregation function applied to matching events (SUM, COUNT, or MAX).

    • functionField (string) –

      The event property key the aggregation function operates on. Required for SUM and MAX; ignored for COUNT.

    • groupBy (list) – [REQUIRED]

      The event fields to group aggregated results by.

      • (string) –

        Name of an event property key referenced by a metric filter or aggregation (filter field, functionField, groupBy). Lowercase snake_case, 1-64 characters: letters, digits, and underscores only, starting with a letter. Unlike PropertyKey, dots are not allowed, so a metric can’t reference a property whose key contains a dot.

    • period (string) – [REQUIRED]

      The reset or rollup period for the aggregation.

  • clientToken (string) –

    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.

    This field is autopopulated if not provided.

  • tags (dict) –

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

    • (string) –

      A tag key. Keys that begin with aws: (in any letter case) are reserved and rejected.

      • (string) –

        A tag value.

Return type:

dict

Returns:

Response Syntax

{
    'metric': {
        'appId': 'string',
        'metricId': 'string',
        'name': 'string',
        'description': 'string',
        'eventType': 'string',
        'unitName': 'string',
        'definition': {
            'filters': [
                {
                    'field': 'string',
                    'operator': 'EQUALS'|'NOT_EQUALS'|'IN'|'NOT_IN',
                    'values': [
                        'string',
                    ]
                },
            ],
            'function': 'SUM'|'COUNT'|'MAX',
            'functionField': 'string',
            'groupBy': [
                'string',
            ],
            'period': 'MONTHLY'
        },
        'arn': 'string',
        'stage': 'DRAFT'|'PUBLISHED'
    }
}

Response Structure

  • (dict) –

    Output for CreateMetric.

    • metric (dict) –

      The newly created metric, in the app’s draft. It goes live on the next app-level PublishDraft.

      • appId (string) –

        The ID of the app the metric belongs to.

      • metricId (string) –

        The ID of the metric. We assign this value when you create the metric; it is unique within the app. Treat it as opaque.

      • name (string) –

        A human-readable display name for the metric.

      • description (string) –

        A description of what the metric measures.

      • eventType (string) –

        The event type this metric aggregates.

      • unitName (string) –

        The unit of measure for the metric.

      • definition (dict) –

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

        • filters (list) –

          The predicates selecting which events contribute to the metric. Combined with logical AND.

          • (dict) –

            A single predicate that selects which events contribute to a metric.

            • field (string) –

              The event property key the filter is evaluated against.

            • operator (string) –

              The comparison operator (EQUALS, NOT_EQUALS, IN, or NOT_IN).

            • values (list) –

              The values the field is compared against.

              • (string) –

                A value the field is compared against, 1-256 characters. Single quotes (’) and backslashes () are not allowed.

        • function (string) –

          The aggregation function applied to matching events (SUM, COUNT, or MAX).

        • functionField (string) –

          The event property key the aggregation function operates on. Required for SUM and MAX; ignored for COUNT.

        • groupBy (list) –

          The event fields to group aggregated results by.

          • (string) –

            Name of an event property key referenced by a metric filter or aggregation (filter field, functionField, groupBy). Lowercase snake_case, 1-64 characters: letters, digits, and underscores only, starting with a letter. Unlike PropertyKey, dots are not allowed, so a metric can’t reference a property whose key contains a dot.

        • period (string) –

          The reset or rollup period for the aggregation.

      • arn (string) –

        The Amazon Resource Name (ARN) of the metric. Output only.

      • stage (string) –

        The offering stage this metric was read from: DRAFT or PUBLISHED. Present on metric reads; absent on write responses.

Exceptions

  • AppMonetization.Client.exceptions.AccessDeniedException

  • AppMonetization.Client.exceptions.ValidationException

  • AppMonetization.Client.exceptions.ConflictException

  • AppMonetization.Client.exceptions.InvalidConfigurationException

  • AppMonetization.Client.exceptions.IdempotencyConflictException

  • AppMonetization.Client.exceptions.InternalServerException

  • AppMonetization.Client.exceptions.ServiceQuotaExceededException

  • AppMonetization.Client.exceptions.ResourceNotFoundException

  • AppMonetization.Client.exceptions.RevisionConflictException

  • AppMonetization.Client.exceptions.ThrottlingException