

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 [AWS](https://github.com/awsdocs/aws-doc-sdk-examples)

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS SDKs AWS DMS を使用するためのコード例
<a name="database-migration-service_code_examples"></a>

次のコード例は、 AWS Software Development Kit (SDK) AWS Database Migration Service で を使用する方法を示しています。

*アクション*はより大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。アクションは個々のサービス機能を呼び出す方法を示していますが、コンテキスト内のアクションは、関連するシナリオで確認できます。

**その他のリソース**
+  **[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 SDKs AWS DMS を使用するための基本的な例
<a name="database-migration-service_code_examples_basics"></a>

次のコード例は、 SDKs AWS Database Migration Service で AWS の基本を使用する方法を示しています。

**Contents**
+ [アクション](database-migration-service_code_examples_actions.md)
  + [`CreateReplicationTask`](database-migration-service_example_database-migration-service_CreateReplicationTask_section.md)

# AWS SDKs AWS DMS を使用するためのアクション
<a name="database-migration-service_code_examples_actions"></a>

次のコード例は、 AWS SDKs で個々の AWS DMS アクションを実行する方法を示しています。それぞれの例には、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)

# CLI で `CreateReplicationTask` を使用する
<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 「 Database Migration Service ユーザーガイド*[AWS 」の「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 ]

**Tools for PowerShell V4**  
**例 1: この例では、CdcStartPosition の代わりに CdcStartTime を使用する新しい AWS Database Migration Service レプリケーションタスクを作成します。 CdcStartPosition MigrationType は「full-load-and-cdc」に設定されます。つまり、ターゲットテーブルは空である必要があります。新しいタスクには、Stage のキーと Test のキー値を持つタグが付けられます。このコマンドレットで使用される値の詳細については、 AWS 「 Database Migration Service ユーザーガイド」の「タスクの作成 (https://docs.aws.amazon.com/dms/latest/userguide/CHAP\$1Tasks.Creating.html)」を参照してください。**  

```
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 コマンドレットリファレンス (V4)*」の「[CreateReplicationTask](https://docs.aws.amazon.com/powershell/v4/reference)」を参照してください。

**Tools for PowerShell V5**  
**例 1: この例では、CdcStartPosition の代わりに CdcStartTime を使用する新しい AWS Database Migration Service レプリケーションタスクを作成します。 CdcStartPosition MigrationType は「full-load-and-cdc」に設定されます。つまり、ターゲットテーブルは空である必要があります。新しいタスクには、Stage のキーと Test のキー値を持つタグが付けられます。このコマンドレットで使用される値の詳細については、 AWS 「 Database Migration Service ユーザーガイド」の「タスクの作成 (https://docs.aws.amazon.com/dms/latest/userguide/CHAP\$1Tasks.Creating.html)」を参照してください。**  

```
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 コマンドレットリファレンス (V5)* の「[CreateReplicationTask](https://docs.aws.amazon.com/powershell/v5/reference)」を参照してください。

------