Skip to content

create_view

create_view(
    name: ViewName,
    definition: ViewDefinition,
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    description: Optional[ViewDescription] = None,
    tags: Optional[TagMap] = None,
    client_token: Optional[str] = None,
) -> CreateViewResponse

Creates a new SQL view. A view is a named, reusable SQL query that can be referenced from telemetry queries. View names must be unique within the account and region. Only USER views can be created — MANAGED views are provisioned by AWS.

Parameters:

  • name (ViewName) –

    The name of the view. Must begin with the "view." prefix. View names must be unique within the account and region.

  • definition (ViewDefinition) –

    The SQL query that defines the view.

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

    A description of the view.

  • tags (Optional[TagMap], default: None ) –

    Resource tags.

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

    Idempotency token for safe retries. Retrying with the same token returns the original view instead of creating a duplicate.

Raises:

Examples:

Create a view The following example creates a user view that saves an error-count-by-service query. View names must begin with the view. prefix and be unique within the account and Region. Payloads are shown as JSON; on the wire they are CBOR-encoded.

>>> client.create_view(name='view.service_errors', definition='SELECT resource[\'attributes\'][\'service.name\'] AS service, COUNT(*) AS error_count FROM "logs.default" WHERE severityText = \'ERROR\' GROUP BY service', description='Error counts by service', tags={'Team': 'observability'}, client_token='3f2a9c1e-7b04-4d8a-9e15-6c2b8d0f4a73')
Source code in docs_src/capo_cloudwatchomni/_services/cloud_watch_omni.py
def create_view(
    self,
    name: "capo_cloudwatchomni.types.view_name.ViewName",
    definition: "capo_cloudwatchomni.types.view_definition.ViewDefinition",
    *,
    config_overrides: Optional[CloudWatchOmniClientConfig] = None,
    description: Optional[
        "capo_cloudwatchomni.types.view_description.ViewDescription"
    ] = None,
    tags: Optional["capo_cloudwatchomni.types.tag_map.TagMap"] = None,
    client_token: Optional[str] = None,
) -> "capo_cloudwatchomni.types.create_view_response.CreateViewResponse":
    r"""Creates a new SQL view. A view is a named, reusable SQL query that can be referenced from telemetry queries. View names must be unique within the account and region. Only USER views can be created — MANAGED views are provisioned by AWS.

    Args:
        name: The name of the view. Must begin with the "view." prefix. View names must be unique within the account and region.
        definition: The SQL query that defines the view.
        description: A description of the view.
        tags: Resource tags.
        client_token: Idempotency token for safe retries. Retrying with the same token returns the original view instead of creating a duplicate.

    Raises:
        capo_cloudwatchomni.errors.access_denied_exception.AccessDeniedException: The caller is not authorized to perform this action.
        capo_cloudwatchomni.errors.conflict_exception.ConflictException: The operation could not be completed because of a conflict with the current state of the resource.
        capo_cloudwatchomni.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_cloudwatchomni.errors.throttling_exception.ThrottlingException: The request was throttled due to exceeding the allowed request rate.
        capo_cloudwatchomni.errors.validation_exception.ValidationException: A parameter is specified incorrectly.
        capo_cloudwatchomni.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        Create a view
        The following example creates a user view that saves an error-count-by-service query. View names must begin with the view. prefix and be unique within the account and Region. Payloads are shown as JSON; on the wire they are CBOR-encoded.

        >>> client.create_view(name='view.service_errors', definition='SELECT resource[\'attributes\'][\'service.name\'] AS service, COUNT(*) AS error_count FROM "logs.default" WHERE severityText = \'ERROR\' GROUP BY service', description='Error counts by service', tags={'Team': 'observability'}, client_token='3f2a9c1e-7b04-4d8a-9e15-6c2b8d0f4a73')
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatchomni.types.create_view_request.CreateViewRequest]",
    ) -> OperationResponse[
        "capo_cloudwatchomni.types.create_view_response.CreateViewResponse"
    ]:
        import capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_view

        output, http_response = (
            capo_cloudwatchomni._operations.cloud_watch_omni_frontend.create_view.create_view(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateView")
    )
    input_: capo_cloudwatchomni.types.create_view_request.CreateViewRequest = {
        "name": name,
        "definition": definition,
    }
    if description is not None:
        input_["description"] = description
    if tags is not None:
        input_["tags"] = tags
    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