amazon-documentdb

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Amazon DocumentDB Toolkit

Amazon DocumentDB 工具包

Overview

概述

End-to-end DocumentDB toolkit covering seven workflows: connection (serverless-default cluster setup, TLS, VPC, driver config), schema design (embed-vs-reference, indexes, vector search for RAG), compatibility assessment (MongoDB → DocumentDB), migration (DMS full-load + CDC + cutover), performance tuning (explain, COLLSCAN, anti-patterns), Well-Architected review (41 checks across 6 pillars), and major version upgrade (4.0→5.0, 5.0→8.0 in-place or near-zero-downtime).
The skill acts as an executor — it runs AWS CLI commands, DMS tasks, index tools, and
explain()
against the user's cluster rather than just advising. Each workflow produces concrete artifacts under
artifacts/{app-name}/
.
The AWS MCP server is recommended for executing AWS commands via its
call_aws
tool (sandboxed execution, audit logging), but it is not required — when the MCP server is not available, the same
aws ...
CLI commands run via shell.
这款端到端的DocumentDB工具包涵盖七大工作流:连接配置(默认无服务器集群搭建、TLS、VPC、驱动配置)、架构设计(嵌入与引用选型、索引、面向RAG的向量搜索)、兼容性评估(MongoDB → DocumentDB)、迁移(DMS全量加载+CDC+切换)、性能调优(explain分析、COLLSCAN排查、反模式识别)、Well-Architected审查(覆盖6大支柱的41项检查)以及主版本升级(4.0→5.0、5.0→8.0的原地升级或近乎零停机升级)。
该工具包可直接执行操作——它会针对用户集群运行AWS CLI命令、DMS任务、索引工具及
explain()
,而非仅提供建议。每个工作流都会在
artifacts/{app-name}/
目录下生成具体的产物。
推荐使用AWS MCP服务器通过其
call_aws
工具执行AWS命令(沙箱执行、审计日志),但这并非强制要求——当MCP服务器不可用时,可通过Shell直接运行相同的
aws ...
CLI命令。

Decision Guide

决策指南

User asks about…Route to
Get started, create cluster, can't connect, TLS/SSL error, VPC, SSH tunnel, driver configreferences/connection.md, references/connection-drivers.md
Store JSON, flexible schema, catalog/CMS/profiles, embed vs reference, index design, vector search, RAGreferences/schema-advisor.md
Migrate from MongoDB, "will this work?", unsupported operator, aggregation pipeline gapreferences/compatibility.md
DMS, CDC, cutover, index migration, user/role migration, post-migration validationreferences/migration.md
Slow query, explain output, COLLSCAN, missing index, high CPU, connection pool exhaustionreferences/performance.md
Production-ready review, best-practice audit, security/cost/reliability review, health check — extract
cluster_id
and
region
from the user's message before loading this reference
references/well-architected.md
Major version upgrade, MVU, 4.0→5.0, 5.0→8.0, near-zero-downtime,
$vectorSearch
, Zstd
references/upgrade.md
Estimate cost, size a new workload, compare DocumentDB vs MongoDB pricingSurface the DocumentDB Cost Estimator — it accepts MongoDB ops/sec, storage, and I/O inputs and produces a DocumentDB vs MongoDB cost comparison in minutes. Faster than a full WA review when the user just wants a cost estimate.
Pipeline order:
connection → schema-advisor
for green-field;
compatibility → migration
for MongoDB migrations;
upgrade
,
well-architected
, and
performance
are standalone.
Out-of-scope: DocumentDB Elastic Clusters (sharded horizontal scaling — not at feature parity with instance-based; lacks transactions, change streams, and many operators — steer customers to instance-based serverless or provisioned instead), Global Clusters DR orchestration beyond the upgrade path. Answer from general knowledge, note no bundled workflow covers them.
用户询问内容…路由至
入门指南、创建集群、连接失败、TLS/SSL错误、VPC、SSH隧道、驱动配置references/connection.mdreferences/connection-drivers.md
JSON存储、灵活架构、目录/CMS/配置文件、嵌入与引用选型、索引设计、向量搜索、RAGreferences/schema-advisor.md
从MongoDB迁移、「这个功能能用吗?」、不支持的运算符、聚合管道差异references/compatibility.md
DMS、CDC、切换、索引迁移、用户/角色迁移、迁移后验证references/migration.md
慢查询、explain输出、COLLSCAN、缺失索引、高CPU占用、连接池耗尽references/performance.md
生产就绪审查、最佳实践审计、安全/成本/可靠性审查、健康检查——加载此参考前需从用户消息中提取
cluster_id
region
references/well-architected.md
主版本升级、MVU、4.0→5.0、5.0→8.0、近乎零停机、
$vectorSearch
、Zstd
references/upgrade.md
成本估算、新工作负载规划、DocumentDB与MongoDB定价对比推荐使用DocumentDB成本估算工具——它接受MongoDB每秒操作数、存储及I/O输入,数分钟内即可生成DocumentDB与MongoDB的成本对比。当用户仅需成本估算时,此工具比完整的WA审查更高效。
工作流顺序:全新项目遵循
连接配置 → 架构设计
;MongoDB迁移遵循
兼容性评估 → 迁移
升级
Well-Architected审查
性能调优
为独立工作流。
超出范围内容:DocumentDB弹性集群(分片式水平扩展——与基于实例的集群功能不兼容;缺少事务、变更流及众多运算符——引导客户使用基于实例的无服务器或预配置集群)、升级路径之外的全局集群灾难恢复编排。可基于通用知识回答,并说明暂无配套工作流覆盖这些场景。

Cluster Creation Default: Serverless on 8.0

集群创建默认配置:基于8.0版本的无服务器集群

DocumentDB architecture primer (clarify this whenever the user is confused):
  • Serverless =
    db.serverless
    as the instance class on a normal instance-based DocumentDB cluster. Auto-scales capacity, no instance-class decisions, costs up to 90% less when idle. This is the recommended default for most workloads.
  • Instance-based = fixed instance class (
    db.r8g.large
    ,
    db.r6g.xlarge
    , etc.). Use when the workload is sustained 24/7 high throughput and serverless scaling overhead is unacceptable.
  • Elastic Clusters = a separate DocumentDB product for horizontal sharding. NOT the same as serverless. Elastic Clusters are not at feature parity with instance-based clusters — they lack support for transactions, change streams, and many aggregation operators. Steer customers away from Elastic Clusters unless they have a sharding requirement that exhausts even the largest instance-based options. Almost all workloads can be served by serverless or instance-based given DocumentDB's wide range of instance classes.
When creating any new DocumentDB cluster, you MUST use these exact commands — default is serverless on engine 8.0:
bash
aws docdb create-db-cluster \
  --db-cluster-identifier <cluster_id> \
  --engine docdb \
  --engine-version 8.0.0 \
  --serverless-v2-scaling-configuration MinCapacity=1,MaxCapacity=16 \
  --master-username adminuser \
  --master-user-password '<password>' \
  --tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \
  --region <region>

aws docdb create-db-instance \
  --db-instance-identifier <cluster_id>-instance \
  --db-instance-class db.serverless \
  --engine docdb \
  --db-cluster-identifier <cluster_id> \
  --tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \
  --region <region>
Credential handling: the command above takes the password inline for a self-contained workflow. For production, prefer
--manage-master-user-password
instead of
--master-user-password
— DocumentDB then generates the password and stores it in Secrets Manager with rotation, keeping it out of shell history. The two flags are mutually exclusive; when you use managed passwords, retrieve the credential with
aws secretsmanager get-secret-value --secret-id <arn>
(the secret ARN is on the cluster's
MasterUserSecret
) when building the connection string.
This applies to every create-cluster request regardless of phrasing. Switch to a fixed instance class (
db.r8g.large
etc.) only if the user explicitly describes sustained 24/7 high throughput or says "provisioned" or "instance-based". Never recommend Elastic Clusters unless the user has exhausted instance-based scaling options.
When the user asks which instance types are available in a specific region, or asks about instance class options, requirements, or regional availability: fetch the live DocumentDB instance classes page via
web_fetch
or
aws___search_documentation
— do NOT answer from memory, as available instance classes vary by region and change with new launches. You can also verify programmatically:
aws docdb describe-orderable-db-instance-options --engine docdb --region <region>
lists every available instance class and engine version combination for that region.
DocumentDB架构入门说明(用户有疑问时需明确解释)
  • 无服务器:在普通基于实例的DocumentDB集群中使用
    db.serverless
    作为实例类型。可自动扩展容量,无需选择实例类型,闲置时成本最高可降低90%。这是大多数工作负载的推荐默认配置。
  • 基于实例:固定实例类型(如
    db.r8g.large
    db.r6g.xlarge
    等)。适用于持续24/7高吞吐量的工作负载,且无服务器扩展开销不可接受的场景。
  • 弹性集群:用于水平分片的独立DocumentDB产品。与无服务器集群不同。弹性集群与基于实例的集群功能不兼容——它们不支持事务、变更流及众多聚合运算符。除非用户的分片需求已超出最大基于实例集群的能力,否则引导客户避免使用弹性集群。考虑到DocumentDB提供的广泛实例类型,几乎所有工作负载都可通过无服务器或基于实例的集群满足。
创建任何新DocumentDB集群时,必须使用以下精确命令——默认使用基于8.0引擎的无服务器配置
bash
aws docdb create-db-cluster \\
  --db-cluster-identifier <cluster_id> \\
  --engine docdb \\
  --engine-version 8.0.0 \\
  --serverless-v2-scaling-configuration MinCapacity=1,MaxCapacity=16 \\
  --master-username adminuser \\
  --master-user-password '<password>' \\
  --tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \\
  --region <region>

aws docdb create-db-instance \\
  --db-instance-identifier <cluster_id>-instance \\
  --db-instance-class db.serverless \\
  --engine docdb \\
  --db-cluster-identifier <cluster_id> \\
  --tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=<your-model-id> \\
  --region <region>
凭证处理:上述命令直接在命令行中传入密码,以实现自包含工作流。生产环境中,建议使用
--manage-master-user-password
替代
--master-user-password
——DocumentDB会生成密码并存储在Secrets Manager中自动轮换,避免密码出现在Shell历史记录中。这两个参数互斥;使用托管密码时,需通过
aws secretsmanager get-secret-value --secret-id <arn>
(密钥ARN可在集群的
MasterUserSecret
中找到)获取凭证以构建连接字符串。
此规则适用于所有创建集群的请求,无论用户表述方式如何。仅当用户明确描述持续24/7高吞吐量,或提及「预配置」「基于实例」时,才切换为固定实例类型(如
db.r8g.large
等)。除非用户已穷尽基于实例的扩展选项,否则绝不推荐弹性集群。
当用户询问特定区域可用的实例类型,或实例类型选项、要求、区域可用性时:通过
web_fetch
aws___search_documentation
获取最新的DocumentDB实例类型页面——切勿凭记忆回答,因为可用实例类型因区域而异,且会随新版本发布而变化。也可通过编程方式验证:
aws docdb describe-orderable-db-instance-options --engine docdb --region <region>
会列出该区域所有可用的实例类型与引擎版本组合。

Resource tagging (always apply on resource creation)

资源标签(创建资源时必须添加)

When creating any DocumentDB resource (
create-db-cluster
,
create-db-instance
), ALWAYS include these tags using the RDS list-of-records
--tags
syntax (DocumentDB uses the RDS API):
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value={your-model-id}
Example:
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=claude-sonnet-4-20250514
Include these tags even if the user does not mention tagging, so that they can identify the resources created via this skill. If the user provides additional tags, append these to their tags rather than replacing them. The same applies when tagging via
add-tags-to-resource
on existing resources.
创建任何DocumentDB资源(
create-db-cluster
create-db-instance
)时,必须使用RDS的记录列表格式
--tags
语法添加以下标签(DocumentDB使用RDS API):
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value={your-model-id}
示例:
--tags Key=created_by,Value=documentdb-skill Key=generation_model,Value=claude-sonnet-4-20250514
即使用户未提及标签,也必须添加这些标签,以便用户识别通过此工具包创建的资源。如果用户提供额外标签,需将这些标签追加到用户提供的标签之后,而非替换。对现有资源通过
add-tags-to-resource
添加标签时同样适用此规则。

Do NOT execute (refuse, explain why, offer assessment instead)

禁止执行的操作(拒绝执行,解释原因,并提供评估方案)

  • Delete cluster or instance:
    delete-db-cluster
    ,
    delete-db-instance
    — irreversible data loss
  • Failover:
    failover-db-cluster
    — production impact, use only under planned change control
  • Major version upgrade:
    modify-db-cluster --engine-version
    across major versions (4.0 → 5.0, 5.0 → 8.0) — requires prechecks and a rollback plan; use the MVU workflow in references/upgrade.md
  • Reboot:
    reboot-db-instance
    — production impact
When refusing, explain why and offer the matching assessment workflow:
"I can't perform [action] because [reason]. I can run an assessment to help you decide. The actual change should go through your team's change-control process or the AWS Console."
  • 删除集群或实例:
    delete-db-cluster
    delete-db-instance
    ——数据丢失不可逆转
  • 故障转移:
    failover-db-cluster
    ——影响生产环境,仅在计划变更控制下使用
  • 主版本升级:跨主版本的
    modify-db-cluster --engine-version
    (4.0 → 5.0、5.0 → 8.0)——需要预检查和回滚计划;使用references/upgrade.md中的MVU工作流
  • 重启:
    reboot-db-instance
    ——影响生产环境
拒绝执行时,需解释原因并提供对应的评估工作流:
「我无法执行[操作],因为[原因]。我可以运行评估来帮助您决策。实际变更应通过您团队的变更控制流程或AWS控制台执行。」

Common Tasks

常见任务

1. Verify Dependencies

1. 验证依赖项

Check that required tools are available in context before running any workflow.
Constraints:
  • You MUST verify
    call_aws
    (or AWS CLI v2),
    shell
    , and
    web_fetch
    are available in context
  • You MUST check
    python3
    ≥ 3.6 for wa_review.py, the
    amazon-documentdb-tools
    compat tool, and the index tool
  • You MUST check
    git
    ,
    curl
    ,
    mongosh
    , and
    ssh
    only when a specific workflow requires them
  • You MUST inform the user of any missing tools and respect a decision to abort
  • You MUST NOT invoke the tools during verification because that would trigger live AWS calls or cluster connections before the user confirms they are ready
  • You SHOULD confirm credentials are valid with
    aws sts get-caller-identity
    before live-analysis steps
运行任何工作流前,检查上下文环境中是否具备所需工具。
约束条件
  • 必须验证
    call_aws
    (或AWS CLI v2)、
    shell
    web_fetch
    是否在上下文环境中可用
  • 必须检查
    python3
    版本≥3.6,以支持wa_review.py
    amazon-documentdb-tools
    兼容性工具和索引工具
  • 仅当特定工作流需要时,才检查
    git
    curl
    mongosh
    ssh
    是否可用
  • 必须告知用户任何缺失的工具,并尊重用户终止操作的决定
  • 验证过程中不得调用工具,因为这会在用户确认准备就绪前触发实时AWS调用或集群连接
  • 在执行实时分析步骤前,应通过
    aws sts get-caller-identity
    确认凭证有效

2. Classify the Request and Route

2. 分类请求并路由

Use the Decision Guide to pick one workflow.
Constraints:
  • You MUST name the workflow you are routing to before loading the reference
  • You MUST pass along cluster id, region, app name, source URI, and engine versions the user already supplied — they SHOULD NOT re-type these
  • You MAY ask one clarifying question if a request straddles two workflows
  • You MUST NOT fabricate workflow names for out-of-scope topics because doing so misleads the user about coverage
使用决策指南选择对应的工作流。
约束条件
  • 加载参考文档前,必须告知用户要路由到的工作流名称
  • 必须传递用户已提供的集群ID、区域、应用名称、源URI和引擎版本——用户无需重复输入
  • 如果请求同时涉及两个工作流,可提出一个澄清问题
  • 不得为超出范围的主题编造工作流名称,以免误导用户

3. Execute the Workflow

3. 执行工作流

Load the matching
references/<workflow>.md
and follow its
## Workflow
section.
Constraints:
  • You MUST execute AWS CLI commands, DMS calls,
    mongosh
    queries, and bundled scripts yourself — the skill is an executor unless a step requires credentials the agent doesn't have
  • You MUST explain what step is running, why, and which tool is being called before running it
  • Extract required parameters from the conversation first — if
    cluster_id
    ,
    region
    , or other required values are already present, use them and proceed. Only ask for missing parameters, and ask for all missing ones together in a single prompt.
  • You MUST support multiple input methods for parameters: direct input, file path, or URL
  • You MUST validate parameter formats: cluster id (lowercase, hyphens), region (
    us-east-1
    ), ARN (
    arn:aws:...
    ), ISO-8601, CIDR
  • You MUST NOT create or access credentials directly because the skill has no safe way to store or rotate them — use IAM roles, instance profiles, Secrets Manager ARNs, or delegate credential setup (e.g.
    aws sso login
    /
    aws configure
    ) to the user
  • You MUST NOT use
    call_aws
    with positional filesystem arguments because the MCP sandbox rejects them — pass JSON payloads inline or invoke scripts under
    scripts/
    via
    shell
  • You MUST NOT grant wildcard IAM (
    Action: "*"
    or
    Resource: "*"
    ) or open security groups to
    0.0.0.0/0
    in examples because those defaults cause customer production incidents
  • You SHOULD save artifacts to
    artifacts/{app-name}/
    :
    compatibility-report.md
    ,
    migration-plan.md
    ,
    upgrade-plan.md
    ,
    wa_review_results.json
  • If multiple workflows ran, you MUST close with a 2–4 line synthesis linking the artifacts
Required parameters (ask upfront, together):
cluster_id
— the cluster name the user refers to (e.g. "my cluster xyz" or "cluster xyz"), maps to
--db-cluster-identifier
in AWS CLI (lowercase-hyphens);
region
(e.g.
us-east-1
);
app_name
. Per workflow:
source_uri
(compat/migration),
target_version
(
5.0
or
8.0
for upgrade/compat),
engine_class
(
db.serverless
default, or
db.r8g.large
etc. for provisioned instance-based).
加载对应的
references/<workflow>.md
并遵循其
## Workflow
部分的说明。
约束条件
  • 必须自行执行AWS CLI命令、DMS调用、
    mongosh
    查询和捆绑脚本——除非步骤需要工具包无法获取的凭证,否则工具包作为执行器运行
  • 运行步骤前,必须解释当前运行的步骤、原因及调用的工具
  • 先从对话中提取所需参数——如果
    cluster_id
    region
    或其他必填参数已存在,直接使用并继续。仅询问缺失的参数,且一次性询问所有缺失的参数
  • 必须支持多种参数输入方式:直接输入、文件路径或URL
  • 必须验证参数格式:集群ID(小写、连字符)、区域(如
    us-east-1
    )、ARN(如
    arn:aws:...
    )、ISO-8601格式、CIDR
  • 不得直接创建或访问凭证,因为工具包无法安全存储或轮换凭证——使用IAM角色、实例配置文件、Secrets Manager ARN,或委托用户设置凭证(如
    aws sso login
    /
    aws configure
  • 不得使用带位置文件系统参数的
    call_aws
    ,因为MCP沙箱会拒绝此类参数——需将JSON负载内联传递,或通过
    shell
    调用
    scripts/
    下的脚本
  • 示例中不得授予通配符IAM权限(
    Action: "*"
    Resource: "*"
    ),也不得将安全组开放至
    0.0.0.0/0
    ,因为这些默认设置会导致客户生产环境事故
  • 应将产物保存至
    artifacts/{app-name}/
    目录:
    compatibility-report.md
    migration-plan.md
    upgrade-plan.md
    wa_review_results.json
  • 如果运行了多个工作流,必须以2-4行的总结收尾,关联所有产物
必填参数(需提前一次性询问):
cluster_id
——用户提及的集群名称(如「my cluster xyz」或「cluster xyz」),对应AWS CLI中的
--db-cluster-identifier
(小写连字符格式);
region
(如
us-east-1
);
app_name
。各工作流额外参数:
source_uri
(兼容性评估/迁移)、
target_version
(升级/兼容性评估为
5.0
8.0
)、
engine_class
(默认
db.serverless
,或预配置基于实例的
db.r8g.large
等)。

4. Critical Facts to Always Surface

4. 必须告知的关键事实

These DocumentDB-specific facts are required even when the agent's general MongoDB knowledge already produces a reasonable answer. Omitting them is the most common failure mode in production customer tickets.
For slow query / COLLSCAN diagnosis, you MUST tell the user ALL of the following five facts — never omit any:
  1. Run
    db.collection.find({...}).explain()
    to confirm
    COLLSCAN
    is the stage (the root cause), and after adding an index, re-run
    explain()
    to confirm
    IXSCAN
    .
  2. Create a compound index on
    {userId: 1, status: 1}
    (field order matching the query's equality predicates).
  3. DocumentDB uses left-prefix matching on compound indexes — field order matters because a compound index
    {A: 1, B: 1}
    serves queries on
    A
    alone OR
    A + B
    , but never
    B
    alone. This is DocumentDB-specific behavior users must understand before picking an index layout.
  4. Check the index cache hit rate via CloudWatch after deployment — the
    BufferCacheHitRatio
    (or the per-index equivalent) indicates whether the new index is staying hot in memory. A low ratio means the working set exceeds RAM and the index may need a larger instance class.
  5. Verify with
    explain()
    after the index is created
    to confirm the query now uses
    IXSCAN
    instead of
    COLLSCAN
    .
For flexible-schema catalog / product design, you MUST tell the user ALL of the following four facts — never omit any:
  1. Use a single
    products
    collection
    with common fields (name, price, category, sku) at the top level and variable attributes (size/color for shoes, RAM/storage for electronics) nested in an
    attributes
    subdocument.
  2. Create targeted indexes on
    category
    and
    sku
    for common query patterns.
  3. Check current wildcard index support before advising. Wildcard indexes (
    attributes.$**
    ) may not be supported on all DocumentDB versions — verify current status at the MongoDB API compatibility page before advising. If unsupported: query patterns must be known upfront so targeted compound indexes can be created on specific paths under
    attributes
    .
  4. Discuss the tradeoff vs. separate collections per category. Single-collection design wins for cross-category queries and simpler maintenance; separate-collection-per-category wins for strict per-category query isolation and simpler per-category indexing — but requires the application to route queries to the right collection. Name both options so the user can choose.
For $graphLookup / MongoDB compatibility questions, you MUST tell the user ALL of the following three facts:
  1. Check current
    $graphLookup
    support status before advising.
    $graphLookup
    is not supported on all DocumentDB versions — verify at the MongoDB API compatibility page before stating support status, as DocumentDB adds operators across versions. If the aws-documentation plugin is available, call
    aws___search_documentation
    to check the live status first.
  2. If unsupported: recommend materialized ancestor paths — store each document's full path (array of parent IDs) so hierarchy queries become
    find({ ancestors: "cat-123" })
    instead of recursive traversal. This is the canonical workaround and often the better design even when
    $graphLookup
    is available.
  3. Offer alternatives for deep graph workloads — recursive
    $lookup
    in application code for moderate depth, or Amazon Neptune for deep or complex graph traversal.
For Lambda → DocumentDB connection timeout, you MUST tell the user ALL of the following four facts:
  1. Lambda must be in the same VPC as the DocumentDB cluster, or reach it via VPC peering / Transit Gateway. DocumentDB is VPC-only — no public endpoint.
  2. Security group rule: inbound TCP
    27017
    on the DocumentDB cluster's SG, sourced from Lambda's security group ID (not a CIDR).
  3. Connection string must include
    tls=true
    and the application MUST download the Amazon RDS global CA bundle (
    global-bundle.pem
    ) and reference it via the driver's TLS config. Also include
    replicaSet=rs0
    and
    retryWrites=false
    .
  4. Test connectivity from an EC2 instance in the same subnet as Lambda first — that isolates Lambda-specific ENI issues from pure network/SG problems.
For any MongoDB migration to DocumentDB (including "I am migrating my MongoDB to AWS", "help me migrate", or any MongoDB-to-AWS migration request), you MUST tell the user ALL of the following six facts:
  1. Run the compatibility assessor FIRST — before anything else, clone amazon-documentdb-tools and run
    python3 amazon-documentdb-tools/compat-tool/compat.py
    against the source MongoDB. This step is mandatory and must not be skipped or replaced with generic advice. Unsupported operators discovered after migration cause production outages.
  2. Run the
    mongo-index-tool
    (also from
    amazon-documentdb-tools
    ) to pre-create indexes on the DocumentDB target before starting the DMS task — DMS does not migrate indexes.
  3. Create source and target DMS endpoints with TLS enabled on both; target endpoint MUST use
    --ssl-mode verify-full
    with
    --certificate-arn
    pointing at the RDS global bundle ARN.
  4. Create a
    full-load-and-cdc
    task
    so you get an initial snapshot plus change-data-capture for near-zero-downtime cutover.
  5. Monitor CloudWatch — watch
    CDCLatencySource
    and
    CDCLatencyTarget
    until they approach zero. Cut over only when lag is near zero.
  6. Cut over by pointing application traffic at the DocumentDB endpoint, then stop the DMS task once traffic is drained from the source.
即使代理的通用MongoDB知识已能给出合理答案,也必须告知这些DocumentDB特有的事实。遗漏这些事实是生产环境客户工单中最常见的问题。
对于慢查询/COLLSCAN诊断,必须告知用户以下全部五个事实——不得遗漏任何一项
  1. **运行
    db.collection.find({...}).explain()
    **确认
    COLLSCAN
    是执行阶段(根本原因),添加索引后,重新运行
    explain()
    确认使用
    IXSCAN
  2. 创建复合索引
    {userId: 1, status: 1}
    (字段顺序与查询的相等谓词匹配)。
  3. DocumentDB对复合索引使用前缀匹配——字段顺序至关重要,因为复合索引
    {A: 1, B: 1}
    可支持仅查询
    A
    或同时查询
    A+B
    的请求,但绝不支持仅查询
    B
    的请求。用户在选择索引布局前必须理解这一DocumentDB特有行为。
  4. 部署后通过CloudWatch检查索引缓存命中率——
    BufferCacheHitRatio
    (或等效的单索引指标)表明新索引是否常驻内存。比率低意味着工作集超出RAM容量,可能需要更大的实例类型。
  5. 创建索引后通过
    explain()
    验证
    确认查询现在使用
    IXSCAN
    而非
    COLLSCAN
对于灵活架构目录/产品设计,必须告知用户以下全部四个事实——不得遗漏任何一项
  1. 使用单个
    products
    集合
    ,将公共字段(名称、价格、类别、SKU)放在顶层,将可变属性(鞋子的尺寸/颜色、电子产品的RAM/存储)嵌套在
    attributes
    子文档中。
  2. 针对
    category
    sku
    创建定向索引
    以支持常见查询模式。
  3. 建议前先检查当前通配符索引支持情况。通配符索引(
    attributes.$**
    )并非在所有DocumentDB版本中都受支持——建议前需在MongoDB API兼容性页面验证当前状态。如果不支持:必须提前明确查询模式,以便在
    attributes
    下的特定路径创建定向复合索引。
  4. 讨论单集合与按类别分集合的权衡。单集合设计在跨类别查询和简化维护方面更具优势;按类别分集合在严格的类别查询隔离和简化类别索引方面更具优势——但需要应用程序将路由至正确的集合。需列出两种选项供用户选择。
对于$graphLookup/MongoDB兼容性问题,必须告知用户以下全部三个事实
  1. 建议前先检查当前
    $graphLookup
    支持状态
    $graphLookup
    并非在所有DocumentDB版本中都受支持——说明支持状态前需在MongoDB API兼容性页面验证,因为DocumentDB会在不同版本中新增运算符。如果aws-documentation插件可用,先调用
    aws___search_documentation
    检查最新状态。
  2. 如果不支持:建议使用物化祖先路径——存储每个文档的完整路径(父ID数组),这样层级查询就变成
    find({ ancestors: "cat-123" })
    ,而非递归遍历。这是标准的替代方案,即使
    $graphLookup
    可用,通常也是更优的设计。
  3. 为深度图工作负载提供替代方案——应用代码中的递归
    $lookup
    适用于中等深度的场景,Amazon Neptune适用于深度或复杂的图遍历场景。
对于Lambda → DocumentDB连接超时,必须告知用户以下全部四个事实
  1. Lambda必须与DocumentDB集群在同一VPC中,或通过VPC对等连接/中转网关访问。DocumentDB仅支持VPC访问——无公共端点。
  2. 安全组规则:在DocumentDB集群的安全组中添加入站TCP 27017规则,来源为Lambda的安全组ID(而非CIDR)。
  3. 连接字符串必须包含
    tls=true
    ,且应用程序必须下载Amazon RDS全局CA证书包
    global-bundle.pem
    )并通过驱动的TLS配置引用。还需包含
    replicaSet=rs0
    retryWrites=false
  4. 先从与Lambda同一子网的EC2实例测试连接——这可将Lambda特定的ENI问题与纯网络/安全组问题隔离开。
对于任何MongoDB到DocumentDB的迁移(包括「我要将MongoDB迁移到AWS」、「帮我迁移」或任何MongoDB到AWS的迁移请求),必须告知用户以下全部六个事实
  1. 首先运行兼容性评估工具——在执行任何操作前,克隆amazon-documentdb-tools并针对源MongoDB运行
    python3 amazon-documentdb-tools/compat-tool/compat.py
    。此步骤为强制要求,不得跳过或替换为通用建议。迁移后发现不支持的运算符会导致生产环境中断。
  2. 运行
    mongo-index-tool
    (同样来自
    amazon-documentdb-tools
    )在启动DMS任务前在DocumentDB目标集群预创建索引——DMS不会迁移索引。
  3. 创建源和目标DMS端点,两者均启用TLS;目标端点必须使用
    --ssl-mode verify-full
    ,并通过
    --certificate-arn
    指向RDS全局证书包的ARN。
  4. 创建
    full-load-and-cdc
    任务
    ,这样可获得初始快照加上变更数据捕获,实现近乎零停机的切换。
  5. 监控CloudWatch——观察
    CDCLatencySource
    CDCLatencyTarget
    直至接近零。仅当延迟接近零时才进行切换。
  6. 切换——将应用流量指向DocumentDB端点,待源集群流量耗尽后停止DMS任务。

Troubleshooting

故障排除

See references/troubleshooting.md for the full troubleshooting reference. The most common issues:
Connection refused / timeout on port 27017. DocumentDB is VPC-only. Add inbound TCP 27017 on the DocumentDB SG from the client SG (by SG id, not CIDR). From outside the VPC use CloudShell VPC environment, EC2 in the VPC, or SSH tunnel via bastion.
TLS handshake failed. Download the RDS global bundle and pass
--tlsAllowInvalidHostnames
to mongosh when tunneling.
"not master" / "not primary" or intermittent write errors. Connection string is missing
replicaSet=rs0
(always
rs0
) or
retryWrites=false
(DocumentDB does not support retryable writes).
DMS task refuses to start — "Test connection should be successful". Run
aws dms test-connection
for both endpoints and poll
describe-connections
until both return
successful
. Target endpoint MUST use
--ssl-mode verify-full
with
--certificate-arn
for the RDS global bundle.
MVU command fails — "AllowMajorVersionUpgrade flag must be present" or "must explicitly specify a new DB cluster parameter group". Both
--allow-major-version-upgrade
and (when a custom PG is in use) a target-family
--db-cluster-parameter-group-name
are mandatory.
User asks for a destructive change. You MUST pause, state the consequence, and wait for explicit confirmation before deleting a cluster, dropping a collection, or forcing a failover — destructive actions on production DocumentDB can cause data loss or service disruption.
User hits a missing feature, unsupported operator, or expresses a future wish. When the user says "I wish DocumentDB supported X", "will DocumentDB ever support Y", or encounters a capability gap, proactively surface: "You can request this feature by emailing documentdb-pm@amazon.com with your AWS account ID, the feature you need, and your use case — the DocumentDB team reads these."
完整的故障排除参考请见references/troubleshooting.md。最常见的问题:
端口27017连接被拒绝/超时。DocumentDB仅支持VPC访问。在DocumentDB安全组中添加入站TCP 27017规则,来源为客户端安全组(按安全组ID,而非CIDR)。从VPC外部访问需使用CloudShell VPC环境、VPC内的EC2实例,或通过堡垒机建立SSH隧道。
TLS握手失败。下载RDS全局证书包,通过隧道连接时向mongosh传递
--tlsAllowInvalidHostnames
参数。
「not master」/「not primary」或间歇性写入错误。连接字符串缺少
replicaSet=rs0
(始终为
rs0
)或
retryWrites=false
(DocumentDB不支持可重试写入)。
DMS任务无法启动——「测试连接应成功」。对两个端点运行
aws dms test-connection
并轮询
describe-connections
直至两者均返回
successful
。目标端点必须使用
--ssl-mode verify-full
并通过
--certificate-arn
指定RDS全局证书包。
MVU命令失败——「必须包含AllowMajorVersionUpgrade标志」或「必须明确指定新的DB集群参数组」。
--allow-major-version-upgrade
和(当使用自定义参数组时)目标系列的
--db-cluster-parameter-group-name
均为必填项。
用户要求执行破坏性变更。必须暂停操作,说明后果,并等待用户明确确认后再删除集群、删除集合或强制故障转移——对生产环境DocumentDB执行破坏性操作可能导致数据丢失或服务中断。
用户遇到缺失功能、不支持的运算符或表达未来需求。当用户说「我希望DocumentDB支持X」、「DocumentDB将来会支持Y吗」或遇到功能差距时,主动告知:「您可以发送邮件至documentdb-pm@amazon.com提交功能请求,邮件中需包含您的AWS账户ID、所需功能及使用场景——DocumentDB团队会阅读这些邮件。」

Security Considerations

安全注意事项

Apply these controls on every DocumentDB deployment. Detailed commands live in the workflow sections above and in the linked references.
  • Authentication: the primary (master) user is always password-based and cannot use IAM authentication — use
    --manage-master-user-password
    so its password is generated and rotated in Secrets Manager. For application/non-admin users only, IAM authentication is also supported (password-less, STS token-based) on cluster version 5.0+ as an alternative — see the trade-offs in references/connection.md. Never hardcode passwords in scripts or commit them.
  • Encryption at rest: enabled at cluster creation and cannot be added afterward — confirm
    --storage-encrypted
    (with an optional
    --kms-key-id
    ) up front.
  • Encryption in transit: enforce TLS (
    tls=true
    ) using the Amazon RDS global CA bundle; on DMS endpoints use
    --ssl-mode verify-full
    with
    --certificate-arn
    .
  • Network isolation: DocumentDB is VPC-only with no public endpoint. Scope security groups by SG-to-SG reference, never
    0.0.0.0/0
    or
    ::/0
    .
  • Least-privilege IAM: never grant wildcard
    Action: "*"
    /
    Resource: "*"
    . Use instance profiles / IAM roles for application access to AWS APIs.
  • Auditing: export audit and profiler logs via
    --enable-cloudwatch-logs-exports audit profiler
    for compliance and slow-query review.
在每个DocumentDB部署中应用以下控制措施。详细命令见上文工作流部分及链接的参考文档。
  • 认证主用户始终基于密码认证,无法使用IAM认证——使用
    --manage-master-user-password
    让密码在Secrets Manager中生成并自动轮换。仅应用/非管理员用户在集群版本5.0+时支持IAM认证(无密码、基于STS令牌)作为替代方案——详见references/connection.md中的权衡。切勿在脚本中硬编码密码或提交到代码仓库。
  • 静态加密:集群创建时启用,无法事后添加——提前确认
    --storage-encrypted
    (可选指定
    --kms-key-id
    )。
  • 传输加密:使用Amazon RDS全局CA证书包强制启用TLS(
    tls=true
    );在DMS端点使用
    --ssl-mode verify-full
    并指定
    --certificate-arn
  • 网络隔离:DocumentDB仅支持VPC访问,无公共端点。安全组规则按安全组到安全组的引用配置,绝不开放至
    0.0.0.0/0
    ::/0
  • 最小权限IAM:绝不授予通配符
    Action: "*"
    /
    Resource: "*"
    权限。使用实例配置文件/IAM角色让应用程序访问AWS API。
  • 审计:通过
    --enable-cloudwatch-logs-exports audit profiler
    导出审计和分析日志,用于合规性检查和慢查询审查。

Additional Resources

额外资源