createSubscription method

Future<CreateSubscriptionOutput> createSubscription({
  1. required String planFamily,
  2. required String planTier,
  3. required List<String> resourceArns,
  4. ApprovalMode? approvalMode,
  5. String? clientToken,
  6. String? usageLevel,
})

Creates a flat-rate pricing subscription for the specified resources.

When approvalMode is set to IMMEDIATE or is not specified, the subscription is activated immediately.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ResourceNotFoundException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter planFamily : The pricing plan family to subscribe to, such as CloudFront.

Parameter planTier : The tier level for the subscription, such as FREE, PRO, BUSINESS, or PREMIUM.

Parameter resourceArns : The ARNs of the AWS resources to include in the subscription. Specify one or more supported resources.

Parameter approvalMode : Determines whether the subscription requires explicit approval before billing starts. Set to MANUAL to require a separate ApprovePaidSubscription call, or IMMEDIATE to activate the subscription right away. Defaults to IMMEDIATE if not specified.

Parameter clientToken : A unique, case-sensitive identifier that you provide to ensure that the request is handled only once. If you send the same request with the same client token, the API returns the original response without creating a duplicate subscription.

Parameter usageLevel : The usage level within the plan tier. Specify DEFAULT for the base configuration, or a higher level if your plan tier supports it.

Implementation

Future<CreateSubscriptionOutput> createSubscription({
  required String planFamily,
  required String planTier,
  required List<String> resourceArns,
  ApprovalMode? approvalMode,
  String? clientToken,
  String? usageLevel,
}) async {
  final $payload = <String, dynamic>{
    'planFamily': planFamily,
    'planTier': planTier,
    'resourceArns': resourceArns,
    if (approvalMode != null) 'approvalMode': approvalMode.value,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (usageLevel != null) 'usageLevel': usageLevel,
  };
  final response = await _protocol.sendRaw(
    payload: $payload,
    method: 'POST',
    requestUri: '/v1/CreateSubscription',
    exceptionFnMap: _exceptionFns,
  );
  final $json = await _s.jsonFromResponse(response);
  return CreateSubscriptionOutput(
    subscription: Subscription.fromJson($json),
    eTag: _s.extractHeaderStringValue(response.headers, 'ETag')!,
  );
}