

文档 AWS SDK 示例 GitHub 存储库中还有更多 [S AWS DK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用的代码示 AWS DMS 例 AWS SDKs
<a name="database-migration-service_code_examples"></a>

以下代码示例向您展示了如何 AWS Database Migration Service 使用 AWS 软件开发套件 (SDK)。

*操作*是大型程序的代码摘录，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

**更多资源**
+  **[AWS DMS 开发者指南](https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html)** —有关的更多信息 AWS DMS.
+ **[AWS DMS API 参考](https://docs.aws.amazon.com/dms/latest/APIReference/Welcome.html)**-有关所有可用 AWS DMS 操作的详细信息。
+ **[AWS 开发者中心](https://aws.amazon.com/developer/code-examples/?awsf.sdk-code-examples-product=product%23)** — 您可以按类别或全文搜索筛选的代码示例。
+ **[AWS SDK 示例](https://github.com/awsdocs/aws-doc-sdk-examples)** — 包含首选语言完整代码的 GitHub 存储库。包括有关设置和运行代码的说明。

**Contents**
+ [基本功能](database-migration-service_code_examples_basics.md)
  + [操作](database-migration-service_code_examples_actions.md)
    + [`CreateReplicationTask`](database-migration-service_example_database-migration-service_CreateReplicationTask_section.md)

# 使用的基本示 AWS DMS 例 AWS SDKs
<a name="database-migration-service_code_examples_basics"></a>

以下代码示例说明如何使用 with 的基础 AWS Database Migration Service 知识 AWS SDKs。

**Contents**
+ [操作](database-migration-service_code_examples_actions.md)
  + [`CreateReplicationTask`](database-migration-service_example_database-migration-service_CreateReplicationTask_section.md)

# 用于 AWS DMS 使用的操作 AWS SDKs
<a name="database-migration-service_code_examples_actions"></a>

以下代码示例演示了如何使用执行单个 AWS DMS 操作 AWS SDKs。每个示例都包含一个指向的链接 GitHub，您可以在其中找到有关设置和运行代码的说明。

 以下示例仅包括最常用的操作。有关完整列表，请参阅 [AWS Database Migration Service API 参考](https://docs.aws.amazon.com/dms/latest/APIReference/Welcome.html)。

**Topics**
+ [`CreateReplicationTask`](database-migration-service_example_database-migration-service_CreateReplicationTask_section.md)

# 将 `CreateReplicationTask` 与 CLI 配合使用
<a name="database-migration-service_example_database-migration-service_CreateReplicationTask_section"></a>

以下代码示例演示如何使用 `CreateReplicationTask`。

------
#### [ CLI ]

**AWS CLI**  
**创建复制任务**  
以下 `create-replication-task` 示例创建复制任务。  

```
aws dms create-replication-task \
    --replication-task-identifier movedata \
    --source-endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA \
    --target-endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:EOM4SFKCZEYHZBFGAGZT3QEC5U \
    --replication-instance-arn $RI_ARN \
    --migration-type full-load \
    --table-mappings file://table-mappings.json
```
`table-mappings.json` 的内容：  

```
{
    "rules": [
        {
            "rule-type": "selection",
            "rule-id": "1",
            "rule-name": "1",
            "object-locator": {
                "schema-name": "prodrep",
                "table-name": "%"
            },
            "rule-action": "include",
            "filters": []
        }
    ]
}
```
输出：  

```
{
    "ReplicationTask": {
        "ReplicationTaskIdentifier": "moveit2",
        "SourceEndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA",
        "TargetEndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:EOM4SFKCZEYHZBFGAGZT3QEC5U",
        "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE",
        "MigrationType": "full-load",
        "TableMappings": ...output omitted... ,
        "ReplicationTaskSettings": ...output omitted... ,
        "Status": "creating",
        "ReplicationTaskCreationDate": 1590524772.505,
        "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII"
    }
}
```
有关更多信息，请参阅 [AWS D *AWS atabase Migration Service 用户指南*中的处理 DMS 任务](https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Tasks.html)。  
+  有关 API 的详细信息，请参阅*AWS CLI 命令参考[CreateReplicationTask](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/dms/create-replication-task.html)*中的。

------
#### [ PowerShell ]

**适用于 PowerShell V4 的工具**  
**示例 1：此示例创建了一个新的 AWS 数据库迁移服务（Database Migration Service）复制任务，该任务使用 CdcStartTime 代替 CdcStartPosition。设置 MigrationType 为 full-load-and-cdc “”，这意味着目标表必须为空。新任务使用一个标签进行标记，该标签的键为 Stage，键值为 Test。有关此 cmdlet 使用的值的更多信息，请参阅《数据库迁移服务用户指南》https://docs.aws.amazon.com/dms/latest/userguide/CHAP中的创建任务 (\$1tasks.creating.html)。 AWS **  

```
New-DMSReplicationTask -ReplicationInstanceArn "arn:aws:dms:us-east-1:123456789012:rep:EXAMPLE66XFJUWATDJGBEXAMPLE"`
  -CdcStartTime "2019-08-08T12:12:12"`
  -CdcStopPosition "server_time:2019-08-09T12:12:12"`
  -MigrationType "full-load-and-cdc"`
  -ReplicationTaskIdentifier "task1"`
  -ReplicationTaskSetting ""`
  -SourceEndpointArn "arn:aws:dms:us-east-1:123456789012:endpoint:EXAMPLEW5UANC7Y3P4EEXAMPLE"`
  -TableMapping "file:////home/testuser/table-mappings.json"`
  -Tag @{"Key"="Stage";"Value"="Test"}`
  -TargetEndpointArn "arn:aws:dms:us-east-1:123456789012:endpoint:EXAMPLEJZASXWHTWCLNEXAMPLE"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 4) [CreateReplicationTask](https://docs.aws.amazon.com/powershell/v4/reference)中的。

**适用于 PowerShell V5 的工具**  
**示例 1：此示例创建了一个新的 AWS 数据库迁移服务（Database Migration Service）复制任务，该任务使用 CdcStartTime 代替 CdcStartPosition。设置 MigrationType 为 full-load-and-cdc “”，这意味着目标表必须为空。新任务使用一个标签进行标记，该标签的键为 Stage，键值为 Test。有关此 cmdlet 使用的值的更多信息，请参阅《数据库迁移服务用户指南》https://docs.aws.amazon.com/dms/latest/userguide/CHAP中的创建任务 (\$1tasks.creating.html)。 AWS **  

```
New-DMSReplicationTask -ReplicationInstanceArn "arn:aws:dms:us-east-1:123456789012:rep:EXAMPLE66XFJUWATDJGBEXAMPLE"`
  -CdcStartTime "2019-08-08T12:12:12"`
  -CdcStopPosition "server_time:2019-08-09T12:12:12"`
  -MigrationType "full-load-and-cdc"`
  -ReplicationTaskIdentifier "task1"`
  -ReplicationTaskSetting ""`
  -SourceEndpointArn "arn:aws:dms:us-east-1:123456789012:endpoint:EXAMPLEW5UANC7Y3P4EEXAMPLE"`
  -TableMapping "file:////home/testuser/table-mappings.json"`
  -Tag @{"Key"="Stage";"Value"="Test"}`
  -TargetEndpointArn "arn:aws:dms:us-east-1:123456789012:endpoint:EXAMPLEJZASXWHTWCLNEXAMPLE"
```
+  有关 API 的详细信息，请参阅 *AWS Tools for PowerShell Cmdlet 参考 (V* 5) [CreateReplicationTask](https://docs.aws.amazon.com/powershell/v5/reference)中的。

------