createAccessPolicy method

Future<CreateAccessPolicyResponse> createAccessPolicy({
  1. required String name,
  2. required String policy,
  3. required AccessPolicyType type,
  4. String? clientToken,
  5. String? description,
})

Creates a data access policy for OpenSearch Serverless. Access policies limit access to collections and the resources within them, and allow a user to access that data irrespective of the access mechanism or network source. For more information, see Data access control for Amazon OpenSearch Serverless.

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

Parameter name : The name of the policy.

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

Parameter type : The type of policy.

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

Parameter description : A description of the policy. Typically used to store information about the permissions defined in the policy.

Implementation

Future<CreateAccessPolicyResponse> createAccessPolicy({
  required String name,
  required String policy,
  required AccessPolicyType type,
  String? clientToken,
  String? description,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'OpenSearchServerless.CreateAccessPolicy'
  };
  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 CreateAccessPolicyResponse.fromJson(jsonResponse.body);
}