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

调用DocumentDB的describeDBClusters API返回RDS集群该如何过滤?

DocumentDB列举集群返回RDS集群的过滤方案

问题原因

AWS DocumentDB与RDS服务共享集群资源模型,无过滤条件调用describeDBClusters接口时,默认返回同区域下所有类型的数据库集群(包含RDS、Aurora、DocumentDB等),因此会出现返回非DocumentDB集群的情况。

解决方案

优先选择API侧过滤的方案,请求时直接指定过滤器,减少不必要的数据传输:

  • 调用接口时添加engine类型过滤器,指定值为docdb,接口将仅返回DocumentDB类型的集群。

修改后的代码示例如下:

AmazonDocDB docdb= AmazonDocDBClientBuilder.standard().withRegion(Regions.EU_WEST_1).withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
// 构造引擎类型过滤器,仅匹配DocumentDB集群
Filter docdbFilter = new Filter().withName("engine").withValues("docdb");
DescribeDBClustersRequest listRequest = new DescribeDBClustersRequest().withFilters(docdbFilter);

for(DBCluster db : docdb.describeDBClusters(listRequest).getDBClusters()) {
    System.out.println(db);
}

如果需要本地二次校验,可在遍历集群时增加判断:

if ("docdb".equals(db.getEngine())) {
    // 仅处理DocumentDB集群
}

修改后你当前无DocumentDB集群的场景下,列举结果将为空,符合预期。

内容的提问来源于stack exchange,提问作者Ihsan Haikal

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 01:54:07