Encapsulates Amazon Redshift cluster operations.
| 14 | |
| 15 | # snippet-start:[python.example_code.redshift.RedshiftWrapper] |
| 16 | class RedshiftWrapper: |
| 17 | """ |
| 18 | Encapsulates Amazon Redshift cluster operations. |
| 19 | """ |
| 20 | |
| 21 | def __init__(self, redshift_client): |
| 22 | """ |
| 23 | :param redshift_client: A Boto3 Redshift client. |
| 24 | """ |
| 25 | self.client = redshift_client |
| 26 | |
| 27 | # snippet-end:[python.example_code.redshift.RedshiftWrapper] |
| 28 | |
| 29 | @classmethod |
| 30 | def from_client(cls): |
| 31 | """ |
| 32 | Creates a wrapper object from a Boto3 client. |
| 33 | |
| 34 | :return: The wrapper object. |
| 35 | """ |
| 36 | client = boto3.client("redshift") |
| 37 | return cls(client) |
| 38 | |
| 39 | # snippet-start:[python.example_code.redshift.CreateCluster] |
| 40 | def create_cluster( |
| 41 | self, |
| 42 | cluster_identifier, |
| 43 | node_type, |
| 44 | master_username, |
| 45 | master_user_password, |
| 46 | publicly_accessible, |
| 47 | number_of_nodes, |
| 48 | ): |
| 49 | """ |
| 50 | Creates a cluster. |
| 51 | |
| 52 | :param cluster_identifier: The name of the cluster. |
| 53 | :param node_type: The type of node in the cluster. |
| 54 | :param master_username: The master username. |
| 55 | :param master_user_password: The master user password. |
| 56 | :param publicly_accessible: Whether the cluster is publicly accessible. |
| 57 | :param number_of_nodes: The number of nodes in the cluster. |
| 58 | :return: The cluster. |
| 59 | """ |
| 60 | |
| 61 | try: |
| 62 | cluster = self.client.create_cluster( |
| 63 | ClusterIdentifier=cluster_identifier, |
| 64 | NodeType=node_type, |
| 65 | MasterUsername=master_username, |
| 66 | MasterUserPassword=master_user_password, |
| 67 | PubliclyAccessible=publicly_accessible, |
| 68 | NumberOfNodes=number_of_nodes, |
| 69 | ) |
| 70 | return cluster |
| 71 | except ClientError as err: |
| 72 | logging.error( |
| 73 | "Couldn't create a cluster. Here's why: %s: %s", |
no outgoing calls