AWS Database Migration Service (DMS)

AWS Database Migration Service (AWS DMS) is a web service you can use to migrate data from your database that is on-premises, on an Amazon Relational Database Service (Amazon RDS) DB instance, or in a database on an Amazon Elastic Compute Cloud (Amazon EC2) instance to a database on an AWS service. These services can include a database on Amazon RDS or a database on an Amazon EC2 instance. You can also migrate a database from an AWS service to an on-premises database. You can migrate between source and target endpoints that use the same database engine, such as from an Oracle database to an Oracle database. You can also migrate between source and target endpoints that use different database engines, such as from an Oracle database to a PostgreSQL database.

Prerequisite Tasks

To use these operators, you must do a few things:

Generic Parameters

aws_conn_id

Reference to Amazon Web Services Connection ID. If this parameter is set to None then the default boto3 behaviour is used without a connection lookup. Otherwise use the credentials stored in the Connection. Default: aws_default

region_name

AWS Region Name. If this parameter is set to None or omitted then region_name from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

verify

Whether or not to verify SSL certificates.

  • False - Do not validate SSL certificates.

  • path/to/cert/bundle.pem - A filename of the CA cert bundle to use. You can specify this argument if you want to use a different CA cert bundle than the one used by botocore.

If this parameter is set to None or is omitted then verify from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

botocore_config

The provided dictionary is used to construct a botocore.config.Config. This configuration can be used to configure Avoid Throttling exceptions, timeouts, etc.

Example, for more detail about parameters please have a look botocore.config.Config
{
    "signature_version": "unsigned",
    "s3": {
        "us_east_1_regional_endpoint": True,
    },
    "retries": {
      "mode": "standard",
      "max_attempts": 10,
    },
    "connect_timeout": 300,
    "read_timeout": 300,
    "tcp_keepalive": True,
}

If this parameter is set to None or omitted then config_kwargs from AWS Connection Extra Parameter will be used. Otherwise use the specified value instead of the connection value. Default: None

Note

Specifying an empty dictionary, {}, will overwrite the connection configuration for botocore.config.Config

Operators

Create a replication task

To create a replication task you can use DmsCreateTaskOperator.

tests/system/amazon/aws/example_dms.py

create_task = DmsCreateTaskOperator(
    task_id="create_task",
    replication_task_id=dms_replication_task_id,
    source_endpoint_arn=create_assets["source_endpoint_arn"],
    target_endpoint_arn=create_assets["target_endpoint_arn"],
    replication_instance_arn=create_assets["replication_instance_arn"],
    table_mappings=table_mappings,
)

Start a replication task

To start a replication task you can use DmsStartTaskOperator.

tests/system/amazon/aws/example_dms.py

start_task = DmsStartTaskOperator(
    task_id="start_task",
    replication_task_arn=task_arn,
)

Get details of replication tasks

To retrieve the details for a list of replication tasks you can use DmsDescribeTasksOperator.

tests/system/amazon/aws/example_dms.py

describe_tasks = DmsDescribeTasksOperator(
    task_id="describe_tasks",
    describe_tasks_kwargs={
        "Filters": [
            {
                "Name": "replication-instance-arn",
                "Values": [create_assets["replication_instance_arn"]],
            }
        ]
    },
    do_xcom_push=False,
)

Stop a replication task

To stop a replication task you can use DmsStopTaskOperator.

tests/system/amazon/aws/example_dms.py

stop_task = DmsStopTaskOperator(
    task_id="stop_task",
    replication_task_arn=task_arn,
)

Delete a replication task

To delete a replication task you can use DmsDeleteTaskOperator.

tests/system/amazon/aws/example_dms.py

delete_task = DmsDeleteTaskOperator(
    task_id="delete_task",
    replication_task_arn=task_arn,
)

Create a serverless replication config

To create a serverless replication config use DmsCreateReplicationConfigOperator.

tests/system/amazon/aws/example_dms_serverless.py

create_replication_config = DmsCreateReplicationConfigOperator(
    task_id="create_replication_config",
    replication_config_id=replication_id,
    source_endpoint_arn=create_assets["source_endpoint_arn"],
    target_endpoint_arn=create_assets["target_endpoint_arn"],
    compute_config={
        "MaxCapacityUnits": 4,
        "MinCapacityUnits": 1,
        "MultiAZ": False,
        "ReplicationSubnetGroupId": "default",
    },
    replication_type="full-load",
    table_mappings=json.dumps(table_mappings),
    trigger_rule=TriggerRule.ALL_SUCCESS,
)

Describe a serverless replication config

To describe a serverless replication config use DmsDescribeReplicationConfigsOperator.

tests/system/amazon/aws/example_dms_serverless.py

describe_replication_configs = DmsDescribeReplicationConfigsOperator(
    task_id="describe_replication_configs",
    trigger_rule=TriggerRule.ALL_SUCCESS,
)

Start a serverless replication

To start a serverless replication use DmsStartReplicationOperator.

tests/system/amazon/aws/example_dms_serverless.py

replicate = DmsStartReplicationOperator(
    task_id="replicate",
    replication_config_arn="{{ task_instance.xcom_pull(task_ids='create_replication_config', key='return_value') }}",
    replication_start_type="start-replication",
    wait_for_completion=True,
    waiter_delay=60,
    waiter_max_attempts=200,
    trigger_rule=TriggerRule.ALL_SUCCESS,
    deferrable=False,
)

Stop a serverless replication

To stop a serverless replication use DmsStopReplicationOperator.

tests/system/amazon/aws/example_dms_serverless.py

stop_relication = DmsStopReplicationOperator(
    task_id="stop_replication",
    replication_config_arn="{{ task_instance.xcom_pull(task_ids='create_replication_config', key='return_value') }}",
    wait_for_completion=True,
    waiter_delay=120,
    waiter_max_attempts=200,
    trigger_rule=TriggerRule.ALL_SUCCESS,
    deferrable=False,
)

Get the status of a serverless replication

To get the status of a serverless replication use DmsDescribeReplicationsOperator.

tests/system/amazon/aws/example_dms_serverless.py

describe_replications = DmsDescribeReplicationsOperator(
    task_id="describe_replications",
    trigger_rule=TriggerRule.ALL_SUCCESS,
)

Delete a serverless replication configuration

To delete a serverless replication config use DmsDeleteReplicationConfigOperator.

tests/system/amazon/aws/example_dms_serverless.py

delete_replication_config = DmsDeleteReplicationConfigOperator(
    task_id="delete_replication_config",
    wait_for_completion=True,
    waiter_delay=60,
    waiter_max_attempts=200,
    deferrable=False,
    replication_config_arn="{{ task_instance.xcom_pull(task_ids='create_replication_config', key='return_value') }}",
    trigger_rule=TriggerRule.ALL_DONE,
)

Sensors

Wait for a replication task to complete

To check the state of a replication task until it is completed, you can use DmsTaskCompletedSensor.

tests/system/amazon/aws/example_dms.py

await_task_stop = DmsTaskCompletedSensor(
    task_id="await_task_stop",
    replication_task_arn=task_arn,
)

Was this entry helpful?