AWS DMS 使用範例 AWS CLI - AWS Command Line Interface

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

AWS DMS 使用範例 AWS CLI

下列程式碼範例說明如何使用 AWS Command Line Interface 與來執行動作及實作常見案例 AWS DMS。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境和跨服務範例中查看內容中的動作。

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用add-tags-to-resource

AWS CLI

若要將標籤新增至資源

下列add-tags-to-resource範例會將標籤新增至複寫執行個體。

aws dms add-tags-to-resource \ --resource-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE \ --tags Key=Environment,Value=PROD Key=Project,Value=dbMigration

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS Database Migration Service 使用指南》中的標記資源

下列程式碼範例會示範如何使用create-endpoint

AWS CLI

建立端點

下列create-endpoint範例會為 Amazon S3 來源建立端點。

aws dms create-endpoint \ --endpoint-type source \ --engine-name s3 \ --endpoint-identifier src-endpoint \ --s3-settings file://s3-settings.json

s3-settings.json 的內容:

{ "BucketName":"my-corp-data", "BucketFolder":"sourcedata", "ServiceAccessRoleArn":"arn:aws:iam::123456789012:role/my-s3-access-role" }

輸出:

{ "Endpoint": { "EndpointIdentifier": "src-endpoint", "EndpointType": "SOURCE", "EngineName": "s3", "EngineDisplayName": "Amazon S3", "ExtraConnectionAttributes": "bucketFolder=sourcedata;bucketName=my-corp-data;compressionType=NONE;csvDelimiter=,;csvRowDelimiter=\\n;", "Status": "active", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:GUVAFG34EECUOJ6QVZ56DAHT3U", "SslMode": "none", "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "S3Settings": { "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "CsvRowDelimiter": "\\n", "CsvDelimiter": ",", "BucketFolder": "sourcedata", "BucketName": "my-corp-data", "CompressionType": "NONE", "EnableStatistics": true } } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 端點

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateEndpoint中的。

下列程式碼範例會示範如何使用create-event-subscription

AWS CLI

若要列出事件訂閱

下列create-event-subscription範例會建立 Amazon SNS 主題 (my-sns-topic) 的事件訂閱。

aws dms create-event-subscription \ --subscription-name my-dms-events \ --sns-topic-arn arn:aws:sns:us-east-1:123456789012:my-sns-topic

輸出:

{ "EventSubscription": { "CustomerAwsId": "123456789012", "CustSubscriptionId": "my-dms-events", "SnsTopicArn": "arn:aws:sns:us-east-1:123456789012:my-sns-topic", "Status": "creating", "SubscriptionCreationTime": "2020-05-21 21:58:38.598", "Enabled": true } }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

下列程式碼範例會示範如何使用create-replication-instance

AWS CLI

建立複製執行處理

下列create-replication-instance範例會建立複寫執行個體。

aws dms create-replication-instance \ --replication-instance-identifier my-repl-instance \ --replication-instance-class dms.t2.micro \ --allocated-storage 5

輸出:

{ "ReplicationInstance": { "ReplicationInstanceIdentifier": "my-repl-instance", "ReplicationInstanceClass": "dms.t2.micro", "ReplicationInstanceStatus": "creating", "AllocatedStorage": 5, "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-f839b688", "Status": "active" } ], "ReplicationSubnetGroup": { "ReplicationSubnetGroupIdentifier": "default", "ReplicationSubnetGroupDescription": "default", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-42599426", "SubnetAvailabilityZone": { "Name": "us-east-1d" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-6746046b", "SubnetAvailabilityZone": { "Name": "us-east-1f" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-d7c825e8", "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-cbfff283", "SubnetAvailabilityZone": { "Name": "us-east-1b" }, "SubnetStatus": "Active" } ] }, "PreferredMaintenanceWindow": "sat:12:35-sat:13:05", "PendingModifiedValues": {}, "MultiAZ": false, "EngineVersion": "3.3.2", "AutoMinorVersionUpgrade": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/f7bc0f8e-1a3a-4ace-9faa-e8494fa3921a", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:ZK2VQBUWFDBAWHIXHAYG5G2PKY", "PubliclyAccessible": true } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用create-replication-subnet-group

AWS CLI

建立子網路群組

下列create-replication-subnet-group範例會建立由 3 個子網路組成的群組。

aws dms create-replication-subnet-group \ --replication-subnet-group-identifier my-subnet-group \ --replication-subnet-group-description "my subnet group" \ --subnet-ids subnet-da327bf6 subnet-bac383e0 subnet-d7c825e8

輸出:

{ "ReplicationSubnetGroup": { "ReplicationSubnetGroupIdentifier": "my-subnet-group", "ReplicationSubnetGroupDescription": "my subnet group", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-d7c825e8", "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetStatus": "Active" } ] } }

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用指南》中的〈設定複製執行個體的網路

下列程式碼範例會示範如何使用create-replication-task

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 工作

下列程式碼範例會示範如何使用delete-connection

AWS CLI

刪除連接

下列delete-connection範例會取消端點與複製執行個體的關聯。

aws dms delete-connection \ --endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE

輸出:

{ "Connection": { "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA", "Status": "deleting", "EndpointIdentifier": "src-database-1", "ReplicationInstanceIdentifier": "my-repl-instance" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的 https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.Creating.html

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteConnection中的。

下列程式碼範例會示範如何使用delete-endpoint

AWS CLI

刪除端點

下列delete-endpoint範例會刪除端點。

aws dms delete-endpoint \ --endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:OUJJVXO4XZ4CYTSEG5XGMN2R3Y

輸出:

{ "Endpoint": { "EndpointIdentifier": "src-endpoint", "EndpointType": "SOURCE", "EngineName": "s3", "EngineDisplayName": "Amazon S3", "ExtraConnectionAttributes": "bucketFolder=sourcedata;bucketName=my-corp-data;compressionType=NONE;csvDelimiter=,;csvRowDelimiter=\\n;", "Status": "deleting", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:OUJJVXO4XZ4CYTSEG5XGMN2R3Y", "SslMode": "none", "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "S3Settings": { "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "CsvRowDelimiter": "\\n", "CsvDelimiter": ",", "BucketFolder": "sourcedata", "BucketName": "my-corp-data", "CompressionType": "NONE", "EnableStatistics": true } } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 端點

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteEndpoint中的。

下列程式碼範例會示範如何使用delete-event-subscription

AWS CLI

若要刪除事件訂閱

下列delete-event-subscription範例會刪除 Amazon SNS 主題的訂閱。

aws dms delete-event-subscription \ --subscription-name "my-dms-events"

輸出:

{ "EventSubscription": { "CustomerAwsId": "123456789012", "CustSubscriptionId": "my-dms-events", "SnsTopicArn": "arn:aws:sns:us-east-1:123456789012:my-sns-topic", "Status": "deleting", "SubscriptionCreationTime": "2020-05-21 21:58:38.598", "Enabled": true } }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

下列程式碼範例會示範如何使用delete-replication-instance

AWS CLI

刪除複製執行處理

以下 delete-replication-instance 範例會刪除複寫執行個體。

aws dms delete-replication-instance \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE

輸出:

{ "ReplicationInstance": { "ReplicationInstanceIdentifier": "my-repl-instance", "ReplicationInstanceClass": "dms.t2.micro", "ReplicationInstanceStatus": "deleting", "AllocatedStorage": 5, "InstanceCreateTime": 1590011235.952, "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-f839b688", "Status": "active" } ], "AvailabilityZone": "us-east-1e", "ReplicationSubnetGroup": { "ReplicationSubnetGroupIdentifier": "default", "ReplicationSubnetGroupDescription": "default", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-42599426", "SubnetAvailabilityZone": { "Name": "us-east-1d" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-6746046b", "SubnetAvailabilityZone": { "Name": "us-east-1f" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-d7c825e8", "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-cbfff283", "SubnetAvailabilityZone": { "Name": "us-east-1b" }, "SubnetStatus": "Active" } ] }, "PreferredMaintenanceWindow": "wed:11:42-wed:12:12", "PendingModifiedValues": {}, "MultiAZ": true, "EngineVersion": "3.3.2", "AutoMinorVersionUpgrade": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/f7bc0f8e-1a3a-4ace-9faa-e8494fa3921a", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "ReplicationInstancePublicIpAddress": "54.225.120.92", "ReplicationInstancePrivateIpAddress": "172.31.30.121", "ReplicationInstancePublicIpAddresses": [ "54.225.120.92", "3.230.18.248" ], "ReplicationInstancePrivateIpAddresses": [ "172.31.30.121", "172.31.75.90" ], "PubliclyAccessible": true, "SecondaryAvailabilityZone": "us-east-1b" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用delete-replication-subnet-group

AWS CLI

刪除子網路群組

下列delete-replication-subnet-group範例會刪除子網路群組。

aws dms delete-replication-subnet-group \ --replication-subnet-group-identifier my-subnet-group

輸出:

(none)

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用指南》中的〈設定複製執行個體的網路

下列程式碼範例會示範如何使用delete-replication-task

AWS CLI

若要刪除複製工作

下列delete-replication-task範例會刪除複製工作。

aws dms delete-replication-task \ --replication-task-arn arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII

輸出:

{ "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": "deleting", "StopReason": "Stop Reason FULL_LOAD_ONLY_FINISHED", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590789988.677, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 工作

下列程式碼範例會示範如何使用describe-account-attributes

AWS CLI

描述帳號屬性

下列describe-account-attributes範例會列出您 AWS 帳戶的屬性。

aws dms describe-account-attributes

輸出:

{ "AccountQuotas": [ { "AccountQuotaName": "ReplicationInstances", "Used": 1, "Max": 20 }, { "AccountQuotaName": "AllocatedStorage", "Used": 5, "Max": 10000 }, ...remaining output omitted... ], "UniqueAccountIdentifier": "cqahfbfy5xee" }

下列程式碼範例會示範如何使用describe-certificates

AWS CLI

列出可用的憑證

下列describe-certificates範例會列出您 AWS 帳戶中可用的憑證。

aws dms describe-certificates

輸出:

{ "Certificates": [ { "CertificateIdentifier": "my-cert", "CertificateCreationDate": 1543259542.506, "CertificatePem": "-----BEGIN CERTIFICATE-----\nMIID9DCCAtygAwIBAgIBQjANBgkqhkiG9w0BAQ ...U" ... remaining output omittted ... } ] }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 SSL

下列程式碼範例會示範如何使用describe-connections

AWS CLI

描述連線

下列describe-connections範例會列出您在複寫執行個體和端點之間測試過的連線。

aws dms describe-connections

輸出:

{ "Connections": [ { "Status": "successful", "ReplicationInstanceIdentifier": "test", "EndpointArn": "arn:aws:dms:us-east-arn:aws:dms:us-east-1:123456789012:endpoint:ZW5UAN6P4E77EC7YWHK4RZZ3BE", "EndpointIdentifier": "testsrc1", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:6UTDJGBOUS3VI3SUWA66XFJCJQ" } ] }

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用手冊》中的〈建立來源和目標端點

下列程式碼範例會示範如何使用describe-endpoint-types

AWS CLI

列出可用的端點類型

下列describe-endpoint-types範例會列出可用的 MySQL 端點類型。

aws dms describe-endpoint-types \ --filters "Name=engine-name,Values=mysql"

輸出:

{ "SupportedEndpointTypes": [ { "EngineName": "mysql", "SupportsCDC": true, "EndpointType": "source", "EngineDisplayName": "MySQL" }, { "EngineName": "mysql", "SupportsCDC": true, "EndpointType": "target", "EngineDisplayName": "MySQL" } ] }

如需詳細資訊,請參閱資 Database AWS Migration Service 使用指南中的使用 AWS DMS 端點 `__。 < https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.html>

下列程式碼範例會示範如何使用describe-endpoints

AWS CLI

描述端點

下列describe-endpoints範例會列出您 AWS 帳戶中的端點。

aws dms describe-endpoints

輸出:

{ "Endpoints": [ { "Username": "dms", "Status": "active", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:SF2WOFLWYWKVEOHID2EKLP3SJI", "ServerName": "ec2-52-32-48-61.us-west-2.compute.amazonaws.com", "EndpointType": "SOURCE", "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/94d5c4e7-4e4c-44be-b58a-c8da7adf57cd", "DatabaseName": "test", "EngineName": "mysql", "EndpointIdentifier": "pri100", "Port": 8193 }, { "Username": "admin", "Status": "active", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:TJJZCIH3CJ24TJRU4VC32WEWFR", "ServerName": "test.example.com", "EndpointType": "SOURCE", "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/2431021b-1cf2-a2d4-77b2-59a9e4bce323", "DatabaseName": "EMPL", "EngineName": "oracle", "EndpointIdentifier": "test", "Port": 1521 } ] }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 端點

下列程式碼範例會示範如何使用describe-event-categories

AWS CLI

描述事件類別

下列describe-event-categories範例會列出可用的事件類別。

aws dms describe-event-categories

輸出:

{ "EventCategoryGroupList": [ { "SourceType": "replication-instance", "EventCategories": [ "low storage", "configuration change", "maintenance", "deletion", "creation", "failover", "failure" ] }, { "SourceType": "replication-task", "EventCategories": [ "configuration change", "state change", "deletion", "creation", "failure" ] } ] }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

下列程式碼範例會示範如何使用describe-event-subscriptions

AWS CLI

描述事件訂閱

下列describe-event-subscriptions範例列出 Amazon SNS 主題的事件訂閱。

aws dms describe-event-subscriptions

輸出:

{ "EventSubscriptionsList": [ { "CustomerAwsId": "123456789012", "CustSubscriptionId": "my-dms-events", "SnsTopicArn": "arn:aws:sns:us-east-1:123456789012:my-sns-topic", "Status": "deleting", "SubscriptionCreationTime": "2020-05-21 22:28:51.924", "Enabled": true } ] }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

下列程式碼範例會示範如何使用describe-events

AWS CLI

若要列出 DMS 事件

下列describe-events範例會列出源自複寫執行個體的事件。

aws dms describe-events \ --source-type "replication-instance"

輸出:

{ "Events": [ { "SourceIdentifier": "my-repl-instance", "SourceType": "replication-instance", "Message": "Replication application shutdown", "EventCategories": [], "Date": 1590771645.776 } ] }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeEvents中的。

下列程式碼範例會示範如何使用describe-orderable-replication-instances

AWS CLI

說明可訂購的複製執行個體

下列describe-orderable-replication-instances範例會列出您可訂購的複製執行個體類型。

aws dms describe-orderable-replication-instances

輸出:

{ "OrderableReplicationInstances": [ { "EngineVersion": "3.3.2", "ReplicationInstanceClass": "dms.c4.2xlarge", "StorageType": "gp2", "MinAllocatedStorage": 5, "MaxAllocatedStorage": 6144, "DefaultAllocatedStorage": 100, "IncludedAllocatedStorage": 100, "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f" ] }, { "EngineVersion": "3.3.2", "ReplicationInstanceClass": "dms.c4.4xlarge", "StorageType": "gp2", "MinAllocatedStorage": 5, "MaxAllocatedStorage": 6144, "DefaultAllocatedStorage": 100, "IncludedAllocatedStorage": 100, "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f" ] }, ...remaining output omitted... }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用describe-refresh-schemas-status

AWS CLI

列出端點的重新整理狀態

下列describe-refresh-schemas-status範例會傳回先前重新整理要求的狀態。

aws dms describe-refresh-schemas-status \ --endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA

輸出:

{ "RefreshSchemasStatus": { "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "Status": "successful", "LastRefreshDate": 1590786544.605 } }

下列程式碼範例會示範如何使用describe-replication-instances

AWS CLI

描述複製執行個體

下列describe-replication-instances範例會列出您 AWS 帳戶中的複寫執行個體。

aws dms describe-replication-instances

輸出:

{ "ReplicationInstances": [ { "ReplicationInstanceIdentifier": "my-repl-instance", "ReplicationInstanceClass": "dms.t2.micro", "ReplicationInstanceStatus": "available", "AllocatedStorage": 5, "InstanceCreateTime": 1590011235.952, "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-f839b688", "Status": "active" } ], "AvailabilityZone": "us-east-1e", "ReplicationSubnetGroup": { "ReplicationSubnetGroupIdentifier": "default", "ReplicationSubnetGroupDescription": "default", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-42599426", "SubnetAvailabilityZone": { "Name": "us-east-1d" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-6746046b", "SubnetAvailabilityZone": { "Name": "us-east-1f" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-d7c825e8", "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-cbfff283", "SubnetAvailabilityZone": { "Name": "us-east-1b" }, "SubnetStatus": "Active" } ] }, "PreferredMaintenanceWindow": "wed:11:42-wed:12:12", "PendingModifiedValues": { "MultiAZ": true }, "MultiAZ": false, "EngineVersion": "3.3.2", "AutoMinorVersionUpgrade": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/f7bc0f8e-1a3a-4ace-9faa-e8494fa3921a", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "ReplicationInstancePublicIpAddress": "3.230.18.248", "ReplicationInstancePrivateIpAddress": "172.31.75.90", "ReplicationInstancePublicIpAddresses": [ "3.230.18.248" ], "ReplicationInstancePrivateIpAddresses": [ "172.31.75.90" ], "PubliclyAccessible": true, "FreeUntil": 1590194829.267 } ] }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用describe-replication-subnet-groups

AWS CLI

顯示可用的子網路群組

下列describe-replication-subnet-groups範例會列出可用的子網路群組。

aws dms describe-replication-subnet-groups \ --filter "Name=replication-subnet-group-id,Values=my-subnet-group"

輸出:

{ "ReplicationSubnetGroups": [ { "ReplicationSubnetGroupIdentifier": "my-subnet-group", "ReplicationSubnetGroupDescription": "my subnet group", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-d7c825e8", "SubnetAvailabilityZone": { "Name": "us-east-1e" }, "SubnetStatus": "Active" } ] } ] }

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用指南》中的〈設定複製執行個體的網路

下列程式碼範例會示範如何使用describe-replication-task-assessment-results

AWS CLI

若要列出複寫作業評估的結果

下列describe-replication-task-assessment-results範例會列出先前作業評估的結果。

aws dms describe-replication-task-assessment-results

輸出:

{ "ReplicationTaskAssessmentResults": [ { "ReplicationTaskIdentifier": "moveit2", "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII", "ReplicationTaskLastAssessmentDate": 1590790230.0, "AssessmentStatus": "No issues found", "AssessmentResultsFile": "moveit2/2020-05-29-22-10" } ] }

如需詳細資訊,請參閱 < 資 AWS Database Migration Service 使用指南 > 中的 < 建立工作評估報告 >。

下列程式碼範例會示範如何使用describe-replication-tasks

AWS CLI

描述複製任務

下列describe-replication-tasks範例說明目前的複寫工作。

aws dms describe-replication-tasks

輸出:

{ "ReplicationTasks": [ { "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": "stopped", "StopReason": "Stop Reason FULL_LOAD_ONLY_FINISHED", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590619805.212, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII", "ReplicationTaskStats": { "FullLoadProgressPercent": 100, "ElapsedTimeMillis": 0, "TablesLoaded": 0, "TablesLoading": 0, "TablesQueued": 0, "TablesErrored": 0, "FreshStartDate": 1590619811.528, "StartDate": 1590619811.528, "StopDate": 1590619842.068 } } ] }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 工作

下列程式碼範例會示範如何使用describe-schemas

AWS CLI

取消寫資料庫綱要的步驟

下列describe-schemas範例會列出端點上的可用資料表。

aws dms describe-schemas \ --endpoint-arn "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA"

輸出:

{ "Schemas": [ "prodrep" ] }

如需詳細資訊,請參閱 < AWS Database Migration Service 使用指南 > 中的主題標題。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DescribeSchemas中的。

下列程式碼範例會示範如何使用list-tags-for-resource

AWS CLI

若要列出資源的標籤

下列list-tags-for-resource範例會列出複寫執行個體的標籤。

aws dms list-tags-for-resource \ --resource-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE

輸出:

{ "TagList": [ { "Key": "Project", "Value": "dbMigration" }, { "Key": "Environment", "Value": "PROD" } ] }

如需詳細資訊,請參閱《AWS Database Migration Service 使用指南》中的標記資源

下列程式碼範例會示範如何使用modify-endpoint

AWS CLI

修改端點

下列modify-endpoint範例會將額外的連線屬性新增至端點。

aws dms modify-endpoint \ --endpoint-arn "arn:aws:dms:us-east-1:123456789012:endpoint:GUVAFG34EECUOJ6QVZ56DAHT3U" \ --extra-connection-attributes "compressionType=GZIP"

輸出:

{ "Endpoint": { "EndpointIdentifier": "src-endpoint", "EndpointType": "SOURCE", "EngineName": "s3", "EngineDisplayName": "Amazon S3", "ExtraConnectionAttributes": "compressionType=GZIP;csvDelimiter=,;csvRowDelimiter=\\n;", "Status": "active", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:GUVAFG34EECUOJ6QVZ56DAHT3U", "SslMode": "none", "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "S3Settings": { "ServiceAccessRoleArn": "arn:aws:iam::123456789012:role/my-s3-access-role", "CsvRowDelimiter": "\\n", "CsvDelimiter": ",", "BucketFolder": "", "BucketName": "", "CompressionType": "GZIP", "EnableStatistics": true } } }

如需詳細資訊,請參閱資 Database AWS Migration Service 使用指南中的使用 AWS DMS 端點 `__。 < https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Endpoints.html>

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ModifyEndpoint中的。

下列程式碼範例會示範如何使用modify-event-subscription

AWS CLI

修改事件訂閱

下列modify-event-subscription範例會變更事件訂閱的來源類型。

aws dms modify-event-subscription \ --subscription-name "my-dms-events" \ --source-type replication-task

輸出:

{ "EventSubscription": { "CustomerAwsId": "123456789012", "CustSubscriptionId": "my-dms-events", "SnsTopicArn": "arn:aws:sns:us-east-1:123456789012:my-sns-topic", "Status": "modifying", "SubscriptionCreationTime": "2020-05-29 17:04:40.262", "SourceType": "replication-task", "Enabled": true } }

如需詳細資訊,請參閱《資AWS Database Migration Service 使用指南》中的〈處理事件與通知

下列程式碼範例會示範如何使用modify-replication-instance

AWS CLI

修改複製執行處理

下列modify-replication-instance範例會修改複寫執行個體,使其使用異地同步備份部署。

aws dms modify-replication-instance \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE \ --multi-az

輸出:

{ "ReplicationInstance": { "ReplicationInstanceIdentifier": "my-repl-instance", "ReplicationInstanceClass": "dms.t2.micro", "ReplicationInstanceStatus": "available", "AllocatedStorage": 5, "InstanceCreateTime": 1590011235.952, ...output omitted... "PendingModifiedValues": { "MultiAZ": true }, "MultiAZ": false, "EngineVersion": "3.3.2", "AutoMinorVersionUpgrade": true, "KmsKeyId": "arn:aws:kms:us-east-1:123456789012:key/f7bc0f8e-1a3a-4ace-9faa-e8494fa3921a", ...output omitted... } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用modify-replication-subnet-group

AWS CLI

修改子網路群組

下列modify-replication-subnet-group範例會變更與子網路群組相關聯的子網路清單。

aws dms modify-replication-subnet-group \ --replication-subnet-group-identifier my-subnet-group \ --subnet-id subnet-da327bf6 subnet-bac383e0

輸出:

{ "ReplicationSubnetGroup": { "ReplicationSubnetGroupIdentifier": "my-subnet-group", "ReplicationSubnetGroupDescription": "my subnet group", "VpcId": "vpc-136a4c6a", "SubnetGroupStatus": "Complete", "Subnets": [ { "SubnetIdentifier": "subnet-da327bf6", "SubnetAvailabilityZone": { "Name": "us-east-1a" }, "SubnetStatus": "Active" }, { "SubnetIdentifier": "subnet-bac383e0", "SubnetAvailabilityZone": { "Name": "us-east-1c" }, "SubnetStatus": "Active" } ] } }

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用指南》中的〈設定複製執行個體的網路

下列程式碼範例會示範如何使用modify-replication-task

AWS CLI

修改複製工作

下列modify-replication-task範例會變更任務的表格對應。

aws dms modify-replication-task \ --replication-task-arn "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" \ --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": "ACCT_%" }, "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": "modifying", "StopReason": "Stop Reason FULL_LOAD_ONLY_FINISHED", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590789424.653, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 工作

下列程式碼範例會示範如何使用reboot-replication-instance

AWS CLI

重新啟動複製執行個體

以下 reboot-replication-instance 範例會重新開機複寫執行個體。

aws dms reboot-replication-instance \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE

輸出:

{ "ReplicationInstance": { "ReplicationInstanceIdentifier": "my-repl-instance", "ReplicationInstanceClass": "dms.t2.micro", "ReplicationInstanceStatus": "rebooting", "AllocatedStorage": 5, "InstanceCreateTime": 1590011235.952, ... output omitted ... } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 複製執行個體。

下列程式碼範例會示範如何使用refresh-schemas

AWS CLI

重新整理資料庫綱要

下列refresh-schemas範例要求 AWS DMS 重新整理端點上的結構描述清單。

aws dms refresh-schemas \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE \ --endpoint-arn "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA"

輸出:

{ "RefreshSchemasStatus": { "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA", "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "Status": "refreshing", "LastRefreshDate": 1590019949.103 } }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考RefreshSchemas中的。

下列程式碼範例會示範如何使用reload-tables

AWS CLI

若要重新整理端點上可用的表格清單

下列reload-tables範例會在端點重新載入可用資料表的清單。

aws dms reload-tables \ --replication-task-arn "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" \ --tables-to-reload "SchemaName=prodrep,TableName=ACCT_BAL"

輸出:

{ "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" }
  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ReloadTables中的。

下列程式碼範例會示範如何使用remove-tags-from-resource

AWS CLI

從複製執行個體移除標記

下列remove-tags-from-resource範例會從複寫執行個體移除標籤。

aws dms remove-tags-from-resource \ --resource-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE \ --tag-keys Environment Project

此命令不會產生輸出。

如需詳細資訊,請參閱《AWS Database Migration Service 使用指南》中的標記資源

下列程式碼範例會示範如何使用start-replication-task-assessment

AWS CLI

若要啟動作業評估

下列start-replication-task-assessment範例會啟動複寫作業評估。

aws dms start-replication-task-assessment \ --replication-task-arn arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII

輸出:

{ "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": "testing", "StopReason": "Stop Reason FULL_LOAD_ONLY_FINISHED", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590789988.677, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" } }

如需詳細資訊,請參閱 < 資 AWS Database Migration Service 使用指南 > 中的 < 建立工作評估報告 >。

下列程式碼範例會示範如何使用start-replication-task

AWS CLI

啟動複製工作

下列command-name範例會列出您 AWS 帳戶中可用的 Widget。

aws dms start-replication-task \ --replication-task-arn arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII \ --start-replication-task-type reload-target

輸出:

{ "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": "starting", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590619805.212, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 工作

下列程式碼範例會示範如何使用stop-replication-task

AWS CLI

若要停止工作

下列stop-replication-task範例會停止工作。

aws dms stop-replication-task \ --replication-task-arn arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII

輸出:

{ "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": "stopping", "ReplicationTaskCreationDate": 1590524772.505, "ReplicationTaskStartDate": 1590789424.653, "ReplicationTaskArn": "arn:aws:dms:us-east-1:123456789012:task:K55IUCGBASJS5VHZJIINA45FII" } }

如需詳細資訊,請參閱資 AWS Database Migration Service 使用指南中的使用 AWS DMS 工作

下列程式碼範例會示範如何使用test-connection

AWS CLI

測試端點的連線

下列test-connection範例會測試是否可從複寫執行個體存取端點。

aws dms test-connection \ --replication-instance-arn arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE \ --endpoint-arn arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA

輸出:

{ "Connection": { "ReplicationInstanceArn": "arn:aws:dms:us-east-1:123456789012:rep:T3OM7OUB5NM2LCVZF7JPGJRNUE", "EndpointArn": "arn:aws:dms:us-east-1:123456789012:endpoint:6GGI6YPWWGAYUVLKIB732KEVWA", "Status": "testing", "EndpointIdentifier": "src-database-1", "ReplicationInstanceIdentifier": "my-repl-instance" } }

如需詳細資訊,請參閱《資 AWS Database Migration Service 使用手冊》中的〈建立來源和目標端點

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考TestConnection中的。