我正在尝试使用 Python 从 AWS 控制台获取 RDS 数据库实例的数量。我能够从 AWS RDS 获得计数,但我无法根据他们的Status: Available.这是我的代码:client3 = boto3.client('rds', aws_access_key_id=access_key, aws_secret_access_key=secret_key,region_name=region)rds = client3.describe_db_instances().filter(query=[{'Name': 'status', 'Values': ['available']}]) # Throws Error as filter and query are no attributesfor rdsdb in rds['DBInstances']:#['DBInstanceStatus'=='available']: rds_count.append(rdsdb)f.writerow(('p_rds_count', len(rds_count)))print("rds->" + str(len(rds_count)))输出: rds = client3.describe_db_instances().filter(query=[{'Name': 'status', 'Values': ['available']}]) AttributeError: 'dict' object has no attribute 'filter'我怎样才能做到这一点?AWS 控制台应该是这样的:Statusavailable
1 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
您可以简单地检查返回的所有实例的状态:
import boto3
rds_client = boto3.client('rds')
instances = rds_client.describe_db_instances()
available = [i['DBInstanceIdentifier'] for i in instances['DBInstances'] if i['DBInstanceStatus'] == 'available']
print len(available)
添加回答
举报
0/150
提交
取消