Create a Redshift cluster using the IAM role and security group created. :param redshift_client: a redshift client instance :param iam_role_arn: IAM role arn to give permission to cluster to communicate with other AWS service :param vpc_security_group_id: vpc group for network setti
(redshift_client, iam_role_arn, vpc_security_group_id)
| 107 | |
| 108 | |
| 109 | def create_cluster(redshift_client, iam_role_arn, vpc_security_group_id): |
| 110 | """ |
| 111 | Create a Redshift cluster using the IAM role and security group created. |
| 112 | :param redshift_client: a redshift client instance |
| 113 | :param iam_role_arn: IAM role arn to give permission to cluster to communicate with other AWS service |
| 114 | :param vpc_security_group_id: vpc group for network setting for cluster |
| 115 | :return: True if cluster created successfully. |
| 116 | """ |
| 117 | |
| 118 | # Cluster Hardware config |
| 119 | cluster_type = config.get('DWH','DWH_CLUSTER_TYPE') |
| 120 | node_type = config.get('DWH', 'DWH_NODE_TYPE') |
| 121 | num_nodes = int(config.get('DWH', 'DWH_NUM_NODES')) |
| 122 | |
| 123 | # Cluster identifiers and credentials |
| 124 | cluster_identifier = config.get('DWH','DWH_CLUSTER_IDENTIFIER') |
| 125 | db_name = config.get('DWH', 'DWH_DB') |
| 126 | database_port=int(config.get('DWH','DWH_PORT')) |
| 127 | master_username = config.get('DWH', 'DWH_DB_USER') |
| 128 | master_user_password = config.get('DWH', 'DWH_DB_PASSWORD') |
| 129 | |
| 130 | # Cluster adding IAM role |
| 131 | iam_role = None |
| 132 | |
| 133 | # Security settings |
| 134 | security_group = config.get('SECURITY_GROUP', 'NAME') |
| 135 | |
| 136 | # Documentation - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/redshift.html?highlight=create_cluster#Redshift.Client.create_cluster |
| 137 | try: |
| 138 | response = redshift_client.create_cluster( |
| 139 | DBName=db_name, |
| 140 | ClusterIdentifier=cluster_identifier, |
| 141 | ClusterType=cluster_type, |
| 142 | NodeType=node_type, |
| 143 | NumberOfNodes=num_nodes, |
| 144 | MasterUsername=master_username, |
| 145 | MasterUserPassword=master_user_password, |
| 146 | VpcSecurityGroupIds=vpc_security_group_id, |
| 147 | IamRoles = [iam_role_arn] |
| 148 | ) |
| 149 | logger.debug(f"Cluster creation response : {response}") |
| 150 | logger.info(f"Cluster creation response code : {response['ResponseMetadata']['HTTPStatusCode']} ") |
| 151 | except Exception as e: |
| 152 | logger.error(f"Exception occured while creating cluster : {e}") |
| 153 | return False |
| 154 | |
| 155 | return (response['ResponseMetadata']['HTTPStatusCode'] == 200) |
| 156 | |
| 157 | |
| 158 | def get_cluster_status(redshift_client, cluster_identifier): |
no outgoing calls
no test coverage detected