【问题标题】:How to check the cluster status of Redshift using boto3 module in Python?如何在 Python 中使用 boto3 模块检查 Redshift 的集群状态?
【发布时间】:2021-03-26 13:39:48
【问题描述】:

我需要使用 Python 检查 Redshift 集群是否已暂停或可用。我知道模块 boto3 进一步提供了一个方法 describe_clusters()。我不确定如何继续为此编写 Python 脚本。

【问题讨论】:

    标签: python-2.7 amazon-redshift boto3


    【解决方案1】:

    你可以试试

        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')
    

    【讨论】:

    • 请在您的答案中添加一些解释,以便其他人可以从中学习
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多