Skip to content

Commit fcf8637

Browse files
author
awstools
committed
feat(client-marketplace-metering): Added ClientToken parameter to MeterUsage API for specifying idempotent requests.
1 parent e23ed85 commit fcf8637

File tree

7 files changed

+152
-51
lines changed

7 files changed

+152
-51
lines changed

clients/client-marketplace-metering/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@smithy/util-middleware": "^4.2.3",
5757
"@smithy/util-retry": "^4.2.3",
5858
"@smithy/util-utf8": "^4.2.0",
59+
"@smithy/uuid": "^1.1.0",
5960
"tslib": "^2.6.2"
6061
},
6162
"devDependencies": {

clients/client-marketplace-metering/src/commands/BatchMeterUsageCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface BatchMeterUsageCommandOutput extends BatchMeterUsageResult, __M
3434
/**
3535
* <important>
3636
* <p>
37-
* The <code>CustomerIdentifier</code> parameter is scheduled for deprecation. Use <code>CustomerAWSAccountID</code> instead.</p>
37+
* The <code>CustomerIdentifier</code> parameter is scheduled for deprecation on March 31, 2026. Use <code>CustomerAWSAccountID</code> instead.</p>
3838
* <p>These parameters are mutually exclusive. You can't specify both <code>CustomerIdentifier</code> and <code>CustomerAWSAccountID</code> in the same request.
3939
* </p>
4040
* </important>

clients/client-marketplace-metering/src/commands/MeterUsageCommand.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ export interface MeterUsageCommandOutput extends MeterUsageResult, __MetadataBea
4343
* <code>MeterUsage</code> can optionally include multiple usage allocations, to provide
4444
* customers with usage data split into buckets by tags that you define (or allow the
4545
* customer to define).</p>
46-
* <p>Usage records are expected to be submitted as quickly as possible after the event that
47-
* is being recorded, and are not accepted more than 6 hours after the event.</p>
46+
* <p>Submit usage records to report events from the previous hour. If you submit records that
47+
* are greater than six hours after events occur, the records won’t be accepted. The timestamp
48+
* in your request determines when an event is recorded. You can only report usage once per hour
49+
* for each dimension. For AMI-based products, this is per dimension and per EC2 instance. For
50+
* container products, this is per dimension and per ECS task or EKS pod. You can’t modify values
51+
* after they’re recorded. If you report usage before the current hour ends, you will be unable to
52+
* report additional usage until the next hour begins.</p>
4853
* <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>
4954
* @example
5055
* Use a bare-bones client and the command you need to make an API call.
@@ -71,6 +76,7 @@ export interface MeterUsageCommandOutput extends MeterUsageResult, __MetadataBea
7176
* ],
7277
* },
7378
* ],
79+
* ClientToken: "STRING_VALUE",
7480
* };
7581
* const command = new MeterUsageCommand(input);
7682
* const response = await client.send(command);
@@ -95,6 +101,9 @@ export interface MeterUsageCommandOutput extends MeterUsageResult, __MetadataBea
95101
* pod for the given {<code>usageDimension</code>, <code>timestamp</code>} with a different
96102
* <code>usageQuantity</code>.</p>
97103
*
104+
* @throws {@link IdempotencyConflictException} (client fault)
105+
* <p>The <code>ClientToken</code> is being used for multiple requests.</p>
106+
*
98107
* @throws {@link InternalServiceErrorException} (server fault)
99108
* <p>An internal error has occurred. Retry your request. If the problem persists, post a
100109
* message with details on the Amazon Web Services forums.</p>

clients/client-marketplace-metering/src/endpoint/ruleset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ f="endpoint",
1919
g="tree",
2020
h="PartitionResult",
2121
i="stringEquals",
22-
j={[w]:true,"default":false,"type":"Boolean"},
23-
k={[w]:false,"type":"String"},
22+
j={[w]:true,"default":false,"type":"boolean"},
23+
k={[w]:false,"type":"string"},
2424
l={[z]:"Endpoint"},
2525
m={[x]:d,[y]:[{[z]:"UseFIPS"},true]},
2626
n={[x]:d,[y]:[{[z]:"UseDualStack"},true]},

clients/client-marketplace-metering/src/models/models_0.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export interface UsageAllocation {
5555
export interface UsageRecord {
5656
/**
5757
* <p>Timestamp, in UTC, for which the usage is being reported.</p>
58-
* <p>Your application can meter usage for up to one hour in the past. Make sure the
58+
* <p>Your application can meter usage for up to six hours in the past. Make sure the
5959
* <code>timestamp</code> value is not before the start of the software usage.</p>
6060
* @public
6161
*/
@@ -454,6 +454,26 @@ export class DuplicateRequestException extends __BaseException {
454454
}
455455
}
456456

457+
/**
458+
* <p>The <code>ClientToken</code> is being used for multiple requests.</p>
459+
* @public
460+
*/
461+
export class IdempotencyConflictException extends __BaseException {
462+
readonly name: "IdempotencyConflictException" = "IdempotencyConflictException";
463+
readonly $fault: "client" = "client";
464+
/**
465+
* @internal
466+
*/
467+
constructor(opts: __ExceptionOptionType<IdempotencyConflictException, __BaseException>) {
468+
super({
469+
name: "IdempotencyConflictException",
470+
$fault: "client",
471+
...opts,
472+
});
473+
Object.setPrototypeOf(this, IdempotencyConflictException.prototype);
474+
}
475+
}
476+
457477
/**
458478
* <p>The endpoint being called is in a Amazon Web Services Region different from your EC2 instance, ECS
459479
* task, or EKS pod. The Region of the Metering Service endpoint and the Amazon Web Services Region of
@@ -526,6 +546,21 @@ export interface MeterUsageRequest {
526546
* @public
527547
*/
528548
UsageAllocations?: UsageAllocation[] | undefined;
549+
550+
/**
551+
* <p>Specifies a unique, case-sensitive identifier that you provide to ensure the idempotency
552+
* of the request. This lets you safely retry the request without accidentally performing the
553+
* same operation a second time. Passing the same value to a later call to an operation
554+
* requires that you also pass the same value for all other parameters. We recommend that you
555+
* use a <a href="https://wikipedia.org/wiki/Universally_unique_identifier">UUID type of
556+
* value</a>.</p>
557+
* <p>If you don't provide this value, then Amazon Web Services generates a random one for
558+
* you.</p>
559+
* <p>If you retry the operation with the same <code>ClientToken</code>, but with different
560+
* parameters, the retry fails with an <code>IdempotencyConflictException</code> error.</p>
561+
* @public
562+
*/
563+
ClientToken?: string | undefined;
529564
}
530565

531566
/**

clients/client-marketplace-metering/src/protocols/Aws_json1_1.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ResponseMetadata as __ResponseMetadata,
2020
SerdeContext as __SerdeContext,
2121
} from "@smithy/types";
22+
import { v4 as generateIdempotencyToken } from "@smithy/uuid";
2223

2324
import { BatchMeterUsageCommandInput, BatchMeterUsageCommandOutput } from "../commands/BatchMeterUsageCommand";
2425
import { MeterUsageCommandInput, MeterUsageCommandOutput } from "../commands/MeterUsageCommand";
@@ -32,6 +33,7 @@ import {
3233
DisabledApiException,
3334
DuplicateRequestException,
3435
ExpiredTokenException,
36+
IdempotencyConflictException,
3537
InternalServiceErrorException,
3638
InvalidCustomerIdentifierException,
3739
InvalidEndpointRegionException,
@@ -230,6 +232,9 @@ const de_CommandError = async (output: __HttpResponse, context: __SerdeContext):
230232
case "DuplicateRequestException":
231233
case "com.amazonaws.marketplacemetering#DuplicateRequestException":
232234
throw await de_DuplicateRequestExceptionRes(parsedOutput, context);
235+
case "IdempotencyConflictException":
236+
case "com.amazonaws.marketplacemetering#IdempotencyConflictException":
237+
throw await de_IdempotencyConflictExceptionRes(parsedOutput, context);
233238
case "InvalidEndpointRegionException":
234239
case "com.amazonaws.marketplacemetering#InvalidEndpointRegionException":
235240
throw await de_InvalidEndpointRegionExceptionRes(parsedOutput, context);
@@ -322,6 +327,22 @@ const de_ExpiredTokenExceptionRes = async (
322327
return __decorateServiceException(exception, body);
323328
};
324329

330+
/**
331+
* deserializeAws_json1_1IdempotencyConflictExceptionRes
332+
*/
333+
const de_IdempotencyConflictExceptionRes = async (
334+
parsedOutput: any,
335+
context: __SerdeContext
336+
): Promise<IdempotencyConflictException> => {
337+
const body = parsedOutput.body;
338+
const deserialized: any = _json(body);
339+
const exception = new IdempotencyConflictException({
340+
$metadata: deserializeMetadata(parsedOutput),
341+
...deserialized,
342+
});
343+
return __decorateServiceException(exception, body);
344+
};
345+
325346
/**
326347
* deserializeAws_json1_1InternalServiceErrorExceptionRes
327348
*/
@@ -539,6 +560,7 @@ const se_BatchMeterUsageRequest = (input: BatchMeterUsageRequest, context: __Ser
539560
*/
540561
const se_MeterUsageRequest = (input: MeterUsageRequest, context: __SerdeContext): any => {
541562
return take(input, {
563+
ClientToken: [true, (_) => _ ?? generateIdempotencyToken()],
542564
DryRun: [],
543565
ProductCode: [],
544566
Timestamp: (_) => _.getTime() / 1_000,
@@ -603,6 +625,8 @@ const de_BatchMeterUsageResult = (output: any, context: __SerdeContext): BatchMe
603625

604626
// de_ExpiredTokenException omitted.
605627

628+
// de_IdempotencyConflictException omitted.
629+
606630
// de_InternalServiceErrorException omitted.
607631

608632
// de_InvalidCustomerIdentifierException omitted.

0 commit comments

Comments
 (0)