【发布时间】:2021-03-26 13:39:48
【问题描述】:
我需要使用 Python 检查 Redshift 集群是否已暂停或可用。我知道模块 boto3 进一步提供了一个方法 describe_clusters()。我不确定如何继续为此编写 Python 脚本。
【问题讨论】:
标签: python-2.7 amazon-redshift boto3
我需要使用 Python 检查 Redshift 集群是否已暂停或可用。我知道模块 boto3 进一步提供了一个方法 describe_clusters()。我不确定如何继续为此编写 Python 脚本。
【问题讨论】:
标签: python-2.7 amazon-redshift boto3
你可以试试
import boto3
import pandas as pd
DWH_CLUSTER_IDENTIFIER = 'Your clusterId'
KEY='Your AWS Key'
SECRET='Your AWS Secret'
# Get client to connect redshift
redshift = boto3.client('redshift',
region_name="us-east-1",
aws_access_key_id=KEY,
aws_secret_access_key=SECRET
)
# Get cluster list as it is in AWS console
myClusters = redshift.describe_clusters()['Clusters']
if len(myClusters) > 0:
df = pd.DataFrame(myClusters)
myCluster=df[df.ClusterIdentifier==DWH_CLUSTER_IDENTIFIER.lower()]
print("My cluster status is: {}".format(myCluster['ClusterAvailabilityStatus'].item()))
else:
print('No clusters available')
【讨论】: