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:

Operators

Create a replication task

To create a replication task you can use DmsCreateTaskOperator.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

create_task = DmsCreateTaskOperator(
    task_id='create_task',
    replication_task_id=DMS_REPLICATION_TASK_ID,
    source_endpoint_arn='{{ ti.xcom_pull(key="source_endpoint_arn") }}',
    target_endpoint_arn='{{ ti.xcom_pull(key="target_endpoint_arn") }}',
    replication_instance_arn='{{ ti.xcom_pull(key="replication_instance_arn") }}',
    table_mappings=TABLE_MAPPINGS,
)

Start a replication task

To start a replication task you can use DmsStartTaskOperator.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

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.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

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

Stop a replication task

To stop a replication task you can use DmsStopTaskOperator.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

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.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

delete_task = DmsDeleteTaskOperator(
    task_id='delete_task',
    replication_task_arn=task_arn,
    trigger_rule='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.

airflow/providers/amazon/aws/example_dags/example_dms.py[source]

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

Was this entry helpful?