Skip to content

create_lifecycle_policy

create_lifecycle_policy(
    type: LifecyclePolicyType,
    name: PolicyName,
    policy: PolicyDocument,
    *,
    config_overrides: Optional[OpenSearchServerlessClientConfig] = None,
    description: Optional[PolicyDescription] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateLifecyclePolicyResponse

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.

Parameters:

  • type (LifecyclePolicyType) –

    The type of lifecycle policy.

  • name (PolicyName) –

    The name of the lifecycle policy.

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

    A description of the lifecycle policy.

  • policy (PolicyDocument) –

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

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

    A 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/open_search_serverless.py
def create_lifecycle_policy(
    self,
    type: "capo_opensearchserverless.types.lifecycle_policy_type.LifecyclePolicyType",
    name: "capo_opensearchserverless.types.policy_name.PolicyName",
    policy: "capo_opensearchserverless.types.policy_document.PolicyDocument",
    *,
    config_overrides: Optional[OpenSearchServerlessClientConfig] = None,
    description: Optional[
        "capo_opensearchserverless.types.policy_description.PolicyDescription"
    ] = None,
    client_token: Optional[
        "capo_opensearchserverless.types.client_token.ClientToken"
    ] = None,
) -> "capo_opensearchserverless.types.create_lifecycle_policy_response.CreateLifecyclePolicyResponse":
    """<p>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 <a href="https://docs.aws.amazon.com/opensearch-service/latest/developerguide/serverless-lifecycle.html#serverless-lifecycle-create">Creating data lifecycle policies</a>.</p>

    Args:
        type: <p>The type of lifecycle policy.</p>
        name: <p>The name of the lifecycle policy.</p>
        description: <p>A description of the lifecycle policy.</p>
        policy: <p>The JSON policy document to use as the content for the lifecycle policy.</p>
        client_token: <p>A 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.
    """

    def _handler(
        req: "OperationRequest[capo_opensearchserverless.types.create_lifecycle_policy_request.CreateLifecyclePolicyRequest]",
    ) -> OperationResponse[
        "capo_opensearchserverless.types.create_lifecycle_policy_response.CreateLifecyclePolicyResponse"
    ]:
        import capo_opensearchserverless._operations.open_search_serverless.create_lifecycle_policy

        output, http_response = (
            capo_opensearchserverless._operations.open_search_serverless.create_lifecycle_policy.create_lifecycle_policy(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateLifecyclePolicy")
    )
    input_: capo_opensearchserverless.types.create_lifecycle_policy_request.CreateLifecyclePolicyRequest = {
        "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 = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output