createLifecyclePolicy method

Future<CreateLifecyclePolicyResponse> createLifecyclePolicy({
  1. required String name,
  2. required String policy,
  3. required LifecyclePolicyType type,
  4. String? clientToken,
  5. String? description,
})

Creates a lifecyle policy to be applied to OpenSearch Serverless indexes. Lifecycle policies define the number of days or hours to retain the data on an OpenSearch Serverless index. For more information, see Creating data lifecycle policies.

May throw ConflictException. May throw InternalServerException. May throw ServiceQuotaExceededException. May throw ValidationException.

Parameter name : The name of the lifecycle policy.

Parameter policy : The JSON policy document to use as the content for the lifecycle policy.

Parameter type : The type of lifecycle policy.

Parameter clientToken : A unique, case-sensitive identifier to ensure idempotency of the request.

Parameter description : A description of the lifecycle policy.

Implementation

Future<CreateLifecyclePolicyResponse> createLifecyclePolicy({
  required String name,
  required String policy,
  required LifecyclePolicyType type,
  String? clientToken,
  String? description,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'OpenSearchServerless.CreateLifecyclePolicy'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'name': name,
      'policy': policy,
      'type': type.value,
      'clientToken': clientToken ?? _s.generateIdempotencyToken(),
      if (description != null) 'description': description,
    },
  );

  return CreateLifecyclePolicyResponse.fromJson(jsonResponse.body);
}