-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtear_dwh_down.py
44 lines (34 loc) · 1.38 KB
/
tear_dwh_down.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import boto3
from common import get_static_config_instance, EtlConfig
def poll_until_cluster_not_found(redshift_client, cluster_identifier: str) -> None:
try:
cluster_props = redshift_client.describe_clusters(ClusterIdentifier=cluster_identifier)['Clusters'][0]
print(
f"Cluster status (of identifier {cluster_identifier}) = {cluster_props['ClusterStatus']}. " +
"Let's wait for 5 seconds."
)
time.sleep(5)
poll_until_cluster_not_found(redshift_client, cluster_identifier)
except redshift_client.exceptions.ClusterNotFoundFault as e:
print(e)
print(f'Cluster (of identifier {cluster_identifier}) is gone.')
def main() -> None:
etl_config: EtlConfig = get_static_config_instance()
redshift_client = boto3.client('redshift')
redshift_client.delete_cluster(
ClusterIdentifier=etl_config.redshift_cluster.cluster_identifier,
SkipFinalClusterSnapshot=True
)
start_epoch = time.time()
poll_until_cluster_not_found(
redshift_client,
cluster_identifier=etl_config.redshift_cluster.cluster_identifier
)
end_epoch = time.time()
print(
f'Successfully delete cluster with identifier = {etl_config.redshift_cluster.cluster_identifier} ' +
f'in {int(end_epoch - start_epoch)} seconds'
)
if __name__ == '__main__':
main()