Skip to content

create_security_policy async

create_security_policy(
    type: SecurityPolicyType,
    name: PolicyName,
    policy: PolicyDocument,
    *,
    config_overrides: Optional[AsyncOpenSearchServerlessClientConfig] = None,
    description: Optional[PolicyDescription] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateSecurityPolicyResponse

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.

Parameters:

  • type (SecurityPolicyType) –

    The type of security policy.

  • name (PolicyName) –

    The name of the policy.

  • description (Optional[PolicyDescription], default: None ) –

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

  • policy (PolicyDocument) –

    The JSON policy document to use as the content for the new policy.

  • client_token (Optional[ClientToken], default: None ) –

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

Raises:

  • ConflictException –

    When creating a resource, thrown when a resource with the same name already exists or is being created. When deleting a resource, thrown when the resource is not in the ACTIVE, FAILED, or UPDATE_FAILED state.

  • InternalServerException –

    Thrown when an error internal to the service occurs while processing a request.

  • ServiceQuotaExceededException –

    Thrown when you attempt to create more resources than the service allows based on service quotas.

  • ValidationException –

    Thrown when the HTTP request contains invalid input or is missing required input.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_opensearchserverless/_services/async_open_search_serverless.py
async def create_security_policy(
    self,
    type: "capo_opensearchserverless.types.security_policy_type.SecurityPolicyType",
    name: "capo_opensearchserverless.types.policy_name.PolicyName",
    policy: "capo_opensearchserverless.types.policy_document.PolicyDocument",
    *,
    config_overrides: Optional[AsyncOpenSearchServerlessClientConfig] = None,
    description: Optional[
        "capo_opensearchserverless.types.policy_description.PolicyDescription"
    ] = None,
    client_token: Optional[
        "capo_opensearchserverless.types.client_token.ClientToken"
    ] = None,
) -> "capo_opensearchserverless.types.create_security_policy_response.CreateSecurityPolicyResponse":
    """<p>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 <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-network.html">Network access for Amazon OpenSearch Serverless</a> and <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-encryption.html">Encryption at rest for Amazon OpenSearch Serverless</a>.</p>

    Args:
        type: <p>The type of security policy.</p>
        name: <p>The name of the policy.</p>
        description: <p>A description of the policy. Typically used to store information about the permissions defined in the policy.</p>
        policy: <p>The JSON policy document to use as the content for the new policy.</p>
        client_token: <p>Unique, case-sensitive identifier to ensure idempotency of the request.</p>

    Raises:
        capo_opensearchserverless.errors.conflict_exception.ConflictException: <p>When creating a resource, thrown when a resource with the same name already exists or is being created. When deleting a resource, thrown when the resource is not in the ACTIVE, FAILED, or UPDATE_FAILED state.</p>
        capo_opensearchserverless.errors.internal_server_exception.InternalServerException: <p>Thrown when an error internal to the service occurs while processing a request.</p>
        capo_opensearchserverless.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>Thrown when you attempt to create more resources than the service allows based on service quotas.</p>
        capo_opensearchserverless.errors.validation_exception.ValidationException: <p>Thrown when the HTTP request contains invalid input or is missing required input.</p>
        capo_opensearchserverless.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_opensearchserverless.types.create_security_policy_request.CreateSecurityPolicyRequest]",
    ) -> AsyncOperationResponse[
        "capo_opensearchserverless.types.create_security_policy_response.CreateSecurityPolicyResponse"
    ]:
        import capo_opensearchserverless._operations.open_search_serverless.create_security_policy

        (
            output,
            http_response,
        ) = await capo_opensearchserverless._operations.open_search_serverless.create_security_policy.async_create_security_policy(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateSecurityPolicy")
    )
    input_: capo_opensearchserverless.types.create_security_policy_request.CreateSecurityPolicyRequest = {
        "type": type,
        "name": name,
        "policy": policy,
    }
    if description is not None:
        input_["description"] = description
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output