Skip to content

meter_usage async

meter_usage(
    product_code: ProductCode,
    timestamp: Timestamp,
    usage_dimension: UsageDimension,
    *,
    config_overrides: Optional[AsyncMarketplaceMeteringClientConfig] = None,
    usage_quantity: Optional[UsageQuantity] = None,
    dry_run: Optional[Boolean] = None,
    usage_allocations: Optional[UsageAllocations] = None,
    client_token: Optional[ClientToken] = None,
) -> MeterUsageResult

As a seller, your software hosted in the buyer's Amazon Web Services account uses this API action to emit metering records directly to Amazon Web Services Marketplace. You must use the following buyer Amazon Web Services account credentials to sign the API request.

  • For Amazon EC2 deployments, your software must use the IAM role for Amazon EC2 to sign the API call for MeterUsage API operation.

  • For Amazon EKS deployments, your software must use IAM roles for service accounts (IRSA) to sign the API call for the MeterUsage API operation. Using EKS Pod Identity, the node role, or long-term access keys is not supported.

  • For Amazon ECS deployments, your software must use Amazon ECS task IAM role to sign the API call for the MeterUsage API operation. Using the node role or long-term access keys are not supported.

  • For Amazon Bedrock AgentCore Runtime deployments, your software must use the AgentCore Runtime execution role to sign the API call for the MeterUsage API operation. Long-term access keys are not supported.

The handling of MeterUsage requests varies between Amazon Bedrock AgentCore Runtime and non-Amazon Bedrock AgentCore deployments.

  • For non-Amazon Bedrock AgentCore Runtime deployments, you can only report usage once per hour for each dimension. For AMI-based products, this is per dimension and per EC2 instance. For container products, this is per dimension and per ECS task or EKS pod. You can't modify values after they're recorded. If you report usage before a current hour ends, you will be unable to report additional usage until the next hour begins. The Timestamp request parameter is rounded down to the hour and used to enforce this once-per-hour rule for idempotency. For requests that are identical after the Timestamp is rounded down, the API is idempotent and returns the metering record ID.

  • For Amazon Bedrock AgentCore Runtime deployments, you can report usage multiple times per hour for the same dimension. You do not need to aggregate metering records by the hour. You must include an idempotency token in the ClientToken request parameter. If using an Amazon SDK or the Amazon Web Services CLI, you must use the latest version which automatically includes an idempotency token in the ClientToken request parameter so that the request is processed successfully. The Timestamp request parameter is not rounded down to the hour and is not used for duplicate validation. Requests with duplicate Timestamps are aggregated as long as the ClientToken is unique.

If you submit records more than six hours after events occur, the records won't be accepted. The timestamp in your request determines when an event is recorded.

You can optionally include multiple usage allocations, to provide customers with usage data split into buckets by tags that you define or allow the customer to define.

For Amazon Web Services Regions that support MeterUsage, see MeterUsage Region support for Amazon EC2 and MeterUsage Region support for Amazon ECS and Amazon EKS.

Parameters:

  • product_code (ProductCode) –

    Product code is used to uniquely identify a product in Amazon Web Services Marketplace. The product code should be the same as the one used during the publishing of a new product.

  • timestamp (Timestamp) –

    Timestamp, in UTC, for which the usage is being reported. Your application can meter usage for up to six hours in the past. Make sure the timestamp value is not before the start of the software usage.

  • usage_dimension (UsageDimension) –

    It will be one of the fcp dimension name provided during the publishing of the product.

  • usage_quantity (Optional[UsageQuantity], default: None ) –

    Consumption value for the hour. Defaults to 0 if not specified.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the permissions required for the action, but does not make the request. If you have the permissions, the request returns DryRunOperation; otherwise, it returns UnauthorizedException. Defaults to false if not specified.

  • usage_allocations (Optional[UsageAllocations], default: None ) –

    The set of UsageAllocations to submit.

    The sum of all UsageAllocation quantities must equal the UsageQuantity of the MeterUsage request, and each UsageAllocation must have a unique set of tags (include no tags).

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

    Specifies a unique, case-sensitive identifier that you provide to ensure the idempotency of the request. This lets you safely retry the request without accidentally performing the same operation a second time. Passing the same value to a later call to an operation requires that you also pass the same value for all other parameters. We recommend that you use a UUID type of value.

    If you don't provide this value, then Amazon Web Services generates a random one for you.

    If you retry the operation with the same ClientToken, but with different parameters, the retry fails with an IdempotencyConflictException error.

Raises:

  • CustomerNotEntitledException –

    Exception thrown when the customer does not have a valid subscription for the product.

  • DuplicateRequestException –

    A metering record has already been emitted by the same EC2 instance, ECS task, or EKS pod for the given {usageDimension, timestamp} with a different usageQuantity.

  • IdempotencyConflictException –

    The ClientToken is being used for multiple requests.

  • InternalServiceErrorException –

    An internal error has occurred. Retry your request. If the problem persists, post a message with details on the Amazon Web Services forums.

  • InvalidEndpointRegionException –

    The endpoint being called is in a Amazon Web Services Region different from your EC2 instance, ECS task, or EKS pod. The Region of the Metering Service endpoint and the Amazon Web Services Region of the resource must match.

  • InvalidProductCodeException –

    The product code passed does not match the product code used for publishing the product.

  • InvalidTagException –

    The tag is invalid, or the number of tags is greater than 5.

  • InvalidUsageAllocationsException –

    Sum of allocated usage quantities is not equal to the usage quantity.

  • InvalidUsageDimensionException –

    The usage dimension does not match one of the UsageDimensions associated with products.

  • ThrottlingException –

    The calls to the API are throttled.

  • TimestampOutOfBoundsException –

    The timestamp value passed in the UsageRecord is out of allowed range.

    For BatchMeterUsage, if any of the records are outside of the allowed range, the entire batch is not processed. You must remove invalid records and try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_marketplace_metering/_services/async_marketplace_metering.py
async def meter_usage(
    self,
    product_code: "capo_marketplace_metering.types.product_code.ProductCode",
    timestamp: "capo_marketplace_metering.types.timestamp.Timestamp",
    usage_dimension: "capo_marketplace_metering.types.usage_dimension.UsageDimension",
    *,
    config_overrides: Optional[AsyncMarketplaceMeteringClientConfig] = None,
    usage_quantity: Optional[
        "capo_marketplace_metering.types.usage_quantity.UsageQuantity"
    ] = None,
    dry_run: Optional["capo_marketplace_metering.types.boolean.Boolean"] = None,
    usage_allocations: Optional[
        "capo_marketplace_metering.types.usage_allocations.UsageAllocations"
    ] = None,
    client_token: Optional[
        "capo_marketplace_metering.types.client_token.ClientToken"
    ] = None,
) -> "capo_marketplace_metering.types.meter_usage_result.MeterUsageResult":
    """<p>As a seller, your software hosted in the buyer's Amazon Web Services account uses this API action to emit metering records directly to Amazon Web Services Marketplace. You must use the following buyer Amazon Web Services account credentials to sign the API request.</p> <ul> <li> <p>For <b>Amazon EC2</b> deployments, your software must use the <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html">IAM role for Amazon EC2</a> to sign the API call for <code>MeterUsage</code> API operation.</p> </li> <li> <p>For <b>Amazon EKS</b> deployments, your software must use <a href="https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html">IAM roles for service accounts (IRSA)</a> to sign the API call for the <code>MeterUsage</code> API operation. Using <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-identities.html">EKS Pod Identity</a>, the node role, or long-term access keys is not supported.</p> </li> <li> <p>For <b>Amazon ECS</b> deployments, your software must use <a href="https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html">Amazon ECS task IAM</a> role to sign the API call for the <code>MeterUsage</code> API operation. Using the node role or long-term access keys are not supported.</p> </li> <li> <p>For <b>Amazon Bedrock AgentCore Runtime</b> deployments, your software must use the <a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html#runtime-permissions-execution">AgentCore Runtime execution role</a> to sign the API call for the <code>MeterUsage</code> API operation. Long-term access keys are not supported.</p> </li> </ul> <p>The handling of <code>MeterUsage</code> requests varies between Amazon Bedrock AgentCore Runtime and non-Amazon Bedrock AgentCore deployments.</p> <ul> <li> <p>For <b>non-Amazon Bedrock AgentCore Runtime</b> deployments, you can only report usage once per hour for each dimension. For AMI-based products, this is per dimension and per EC2 instance. For container products, this is per dimension and per ECS task or EKS pod. You can't modify values after they're recorded. If you report usage before a current hour ends, you will be unable to report additional usage until the next hour begins. The <code>Timestamp</code> request parameter is rounded down to the hour and used to enforce this once-per-hour rule for idempotency. For requests that are identical after the <code>Timestamp</code> is rounded down, the API is idempotent and returns the metering record ID.</p> </li> <li> <p>For <b>Amazon Bedrock AgentCore Runtime</b> deployments, you can report usage multiple times per hour for the same dimension. You do not need to aggregate metering records by the hour. You must include an idempotency token in the <code>ClientToken</code> request parameter. If using an Amazon SDK or the Amazon Web Services CLI, you must use the latest version which automatically includes an idempotency token in the <code>ClientToken</code> request parameter so that the request is processed successfully. The <code>Timestamp</code> request parameter is not rounded down to the hour and is not used for duplicate validation. Requests with duplicate <code>Timestamps</code> are aggregated as long as the <code>ClientToken</code> is unique.</p> </li> </ul> <p>If you submit records more than six hours after events occur, the records won't be accepted. The timestamp in your request determines when an event is recorded.</p> <p>You can optionally include multiple usage allocations, to provide customers with usage data split into buckets by tags that you define or allow the customer to define.</p> <p>For Amazon Web Services Regions that support <code>MeterUsage</code>, see <a href="https://docs.aws.amazon.com/marketplace/latest/APIReference/metering-regions.html#meterusage-region-support-ec2">MeterUsage Region support for Amazon EC2</a> and <a href="https://docs.aws.amazon.com/marketplace/latest/APIReference/metering-regions.html#meterusage-region-support-ecs-eks">MeterUsage Region support for Amazon ECS and Amazon EKS</a>. </p>

    Args:
        product_code: <p>Product code is used to uniquely identify a product in Amazon Web Services Marketplace. The product code should be the same as the one used during the publishing of a new product.</p>
        timestamp: <p>Timestamp, in UTC, for which the usage is being reported. Your application can meter usage for up to six hours in the past. Make sure the <code>timestamp</code> value is not before the start of the software usage.</p>
        usage_dimension: <p>It will be one of the fcp dimension name provided during the publishing of the product.</p>
        usage_quantity: <p>Consumption value for the hour. Defaults to <code>0</code> if not specified.</p>
        dry_run: <p>Checks whether you have the permissions required for the action, but does not make the request. If you have the permissions, the request returns <code>DryRunOperation</code>; otherwise, it returns <code>UnauthorizedException</code>. Defaults to <code>false</code> if not specified.</p>
        usage_allocations: <p>The set of <code>UsageAllocations</code> to submit.</p> <p>The sum of all <code>UsageAllocation</code> quantities must equal the <code>UsageQuantity</code> of the <code>MeterUsage</code> request, and each <code>UsageAllocation</code> must have a unique set of tags (include no tags).</p>
        client_token: <p>Specifies a unique, case-sensitive identifier that you provide to ensure the idempotency of the request. This lets you safely retry the request without accidentally performing the same operation a second time. Passing the same value to a later call to an operation requires that you also pass the same value for all other parameters. We recommend that you use a <a href="https://wikipedia.org/wiki/Universally_unique_identifier">UUID type of value</a>.</p> <p>If you don't provide this value, then Amazon Web Services generates a random one for you.</p> <p>If you retry the operation with the same <code>ClientToken</code>, but with different parameters, the retry fails with an <code>IdempotencyConflictException</code> error.</p>

    Raises:
        capo_marketplace_metering.errors.customer_not_entitled_exception.CustomerNotEntitledException: <p>Exception thrown when the customer does not have a valid subscription for the product.</p>
        capo_marketplace_metering.errors.duplicate_request_exception.DuplicateRequestException: <p>A metering record has already been emitted by the same EC2 instance, ECS task, or EKS pod for the given {<code>usageDimension</code>, <code>timestamp</code>} with a different <code>usageQuantity</code>.</p>
        capo_marketplace_metering.errors.idempotency_conflict_exception.IdempotencyConflictException: <p>The <code>ClientToken</code> is being used for multiple requests.</p>
        capo_marketplace_metering.errors.internal_service_error_exception.InternalServiceErrorException: <p>An internal error has occurred. Retry your request. If the problem persists, post a message with details on the Amazon Web Services forums.</p>
        capo_marketplace_metering.errors.invalid_endpoint_region_exception.InvalidEndpointRegionException: <p>The endpoint being called is in a Amazon Web Services Region different from your EC2 instance, ECS task, or EKS pod. The Region of the Metering Service endpoint and the Amazon Web Services Region of the resource must match.</p>
        capo_marketplace_metering.errors.invalid_product_code_exception.InvalidProductCodeException: <p>The product code passed does not match the product code used for publishing the product.</p>
        capo_marketplace_metering.errors.invalid_tag_exception.InvalidTagException: <p>The tag is invalid, or the number of tags is greater than 5.</p>
        capo_marketplace_metering.errors.invalid_usage_allocations_exception.InvalidUsageAllocationsException: <p>Sum of allocated usage quantities is not equal to the usage quantity.</p>
        capo_marketplace_metering.errors.invalid_usage_dimension_exception.InvalidUsageDimensionException: <p>The usage dimension does not match one of the <code>UsageDimensions</code> associated with products.</p>
        capo_marketplace_metering.errors.throttling_exception.ThrottlingException: <p>The calls to the API are throttled.</p>
        capo_marketplace_metering.errors.timestamp_out_of_bounds_exception.TimestampOutOfBoundsException: <p>The <code>timestamp</code> value passed in the <code>UsageRecord</code> is out of allowed range.</p> <p>For <code>BatchMeterUsage</code>, if any of the records are outside of the allowed range, the entire batch is not processed. You must remove invalid records and try again.</p>
        capo_marketplace_metering.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_marketplace_metering.types.meter_usage_request.MeterUsageRequest]",
    ) -> AsyncOperationResponse[
        "capo_marketplace_metering.types.meter_usage_result.MeterUsageResult"
    ]:
        import capo_marketplace_metering._operations.awsmp_metering_service.meter_usage

        (
            output,
            http_response,
        ) = await capo_marketplace_metering._operations.awsmp_metering_service.meter_usage.async_meter_usage(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("MeterUsage")
    )
    input_: capo_marketplace_metering.types.meter_usage_request.MeterUsageRequest = {
        "product_code": product_code,
        "timestamp": timestamp,
        "usage_dimension": usage_dimension,
    }
    if usage_quantity is not None:
        input_["usage_quantity"] = usage_quantity
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if usage_allocations is not None:
        input_["usage_allocations"] = usage_allocations
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output