Source code for simple_aws_redshift.redshift.client
# -*- coding: utf-8 -*-"""Improve the original redshift boto3 API.Ref:- https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift.html"""importtypingasTimportbotocore.exceptionsfromfunc_args.apiimportOPT,remove_optionalfrom.modelimport(RedshiftCluster,RedshiftClusterIterProxy,)ifT.TYPE_CHECKING:# pragma: no coverfrommypy_boto3_redshift.clientimportRedshiftClient
[docs]deflist_redshift_clusters(redshift_client:"RedshiftClient",cluster_identifier:str=OPT,tag_keys:list[str]=OPT,tag_values:list[str]=OPT,page_size:int=100,max_items:int=9999,)->RedshiftClusterIterProxy:""" List all Redshift clusters with optional filtering by identifier and tags. Ref: - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift/paginator/DescribeClusters.html :return: `~simple_aws_redshift.redshift.model.RedshiftClusterIterProxy` """# inner generator function to yield objectsdeffunc():paginator=redshift_client.get_paginator("describe_clusters")kwargs=remove_optional(ClusterIdentifier=cluster_identifier,TagKeys=tag_keys,TagValues=tag_values,PaginationConfig={"MaxItems":max_items,"PageSize":page_size,},)response_iterator=paginator.paginate(**remove_optional(**kwargs))forresponseinresponse_iterator:fordctinresponse.get("Clusters",[]):yieldRedshiftCluster(raw_data=dct)# return an iterproxy object that wraps the generatorreturnRedshiftClusterIterProxy(func())
[docs]defget_redshift_cluster(redshift_client:"RedshiftClient",cluster_identifier:str=OPT,)->T.Optional[RedshiftCluster]:""" Get a specific Redshift cluster by identifier. :return: None if the redshift cluster does not exist. Ref: - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift/paginator/DescribeClusters.html """try:redshift_cluster_iterproxy=list_redshift_clusters(redshift_client=redshift_client,cluster_identifier=cluster_identifier,)returnredshift_cluster_iterproxy.one_or_none()exceptbotocore.exceptions.ClientErrorase:ife.response["Error"]["Code"]=="ClusterNotFound":returnNoneelse:raise