createSecurityPolicy method
Creates a security policy to be used by one or more OpenSearch Serverless collections. Security policies provide access to a collection and its OpenSearch Dashboards endpoint from public networks or specific VPC endpoints. They also allow you to secure a collection with a KMS encryption key. For more information, see Network access for Amazon OpenSearch Serverless and Encryption at rest 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 new policy.
Parameter type :
The type of security 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<CreateSecurityPolicyResponse> createSecurityPolicy({
required String name,
required String policy,
required SecurityPolicyType type,
String? clientToken,
String? description,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'OpenSearchServerless.CreateSecurityPolicy'
};
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 CreateSecurityPolicyResponse.fromJson(jsonResponse.body);
}