You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用boto3获取AWS RDS实例故障转移优先级及自动扩缩容相关配置

查询Aurora实例故障转移优先级方案

基础查询方法

首先明确:故障转移优先级(对应接口字段PromotionTier)是Aurora集群专属属性,普通单AZ/多AZ RDS实例不存在该配置,此前查询无结果通常是调用了普通RDS实例查询接口而非集群查询接口。
你可以通过AWS官方的CLI、boto3调用describe-db-clusters接口获取全量实例的优先级配置,刚好适配你的遍历巡检场景:

  • CLI查询命令(指定单集群)
    aws rds describe-db-clusters --db-cluster-identifier <目标集群ID> --query 'DBClusters[0].DBClusterMembers[*].[DBInstanceIdentifier,PromotionTier]' --output table
  • CLI查询命令(遍历当前区域所有集群)
    aws rds describe-db-clusters --query 'DBClusters[*].DBClusterMembers[*].[DBInstanceIdentifier,PromotionTier]' --output table
  • Boto3遍历查询示例代码
import boto3

# 初始化RDS客户端,替换为你要巡检的区域
rds_client = boto3.client('rds', region_name='cn-north-1')
response = rds_client.describe_db_clusters()

for cluster in response.get('DBClusters', []):
    cluster_name = cluster['DBClusterIdentifier']
    print(f"===== 集群 {cluster_name} 实例优先级 =====")
    for instance in cluster['DBClusterMembers']:
        ins_name = instance['DBInstanceIdentifier']
        priority = instance['PromotionTier']
        print(f"实例名:{ins_name},故障转移优先级:{priority}")

返回结果中PromotionTier取值为0-15,数值越小故障转移优先级越高。

自动扩缩容生成副本的优先级查询

自动扩缩容生成的名称格式为application-autoscaling-xxxx的副本,和手动创建的Aurora副本属性完全一致,同样可以通过上述接口直接查询到对应的PromotionTier值。
如果配置自动扩缩容策略时未自定义优先级参数,这类副本的默认故障转移优先级为1,你也可以在创建自动扩缩容策略时指定优先级参数修改默认值。


内容的提问来源于stack exchange,提问作者Nick Barss

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 12:06:04