|
1 | | -# sample-dms-kinesis-rds-mariadb |
2 | | -Sample Application showcasing how to use DMS to create CDC and full load tasks using the CDK in Python. |
| 1 | +# Sample Application showcasing how to use DMS to create CDC |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This scenario demonstrates how to use Database Migration Service (DMS) to create change data capture (CDC) and full load tasks using the Cloud Development Kit in Python. It is a self-contained setup that will create a VPC to host 2 databases, a Kinesis stream, and 4 replication tasks. |
| 6 | + |
| 7 | +## Pre-requisites |
| 8 | + |
| 9 | +- [LocalStack Auth Token](https://docs.localstack.cloud/getting-started/auth-token/) |
| 10 | +- [Python 3.10](https://www.python.org/downloads/) & `pip` |
| 11 | +- [Docker Compose](https://docs.docker.com/compose/install/) |
| 12 | +- [CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with the [`cdklocal`](https://github.com/localstack/aws-cdk-local) wrapper. |
| 13 | + |
| 14 | + |
| 15 | +Start LocalStack Pro with the `LOCALSTACK_AUTH_TOKEN` pre-configured: |
| 16 | + |
| 17 | +```bash |
| 18 | +export LOCALSTACK_AUTH_TOKEN=<your-auth-token> |
| 19 | +docker-compose up |
| 20 | +``` |
| 21 | + |
| 22 | +The Docker Compose file will start LocalStack Pro container and a MariaDB container. The MariaDB container will be used to showcase how to reach a database external to LocalStack. |
| 23 | + |
| 24 | +## Instructions |
| 25 | + |
| 26 | +### Install the dependencies |
| 27 | + |
| 28 | +Install all the dependencies by running the following command: |
| 29 | + |
| 30 | +```bash |
| 31 | +make install |
| 32 | +``` |
| 33 | + |
| 34 | +### Creating the infrastructure |
| 35 | + |
| 36 | +To deploy the infrastructure, you can run the following command: |
| 37 | + |
| 38 | +```bash |
| 39 | +make deploy |
| 40 | +``` |
| 41 | + |
| 42 | +After successful deployment, you will see the following output: |
| 43 | + |
| 44 | +```bash |
| 45 | +Outputs: |
| 46 | +DMsSampleSetupStack.cdcTask1 = arn:aws:dms:us-east-1:000000000000:task:A001NYMR4Z0NK45ZBJT6954RNMGEKL2PQ9XQYR4 |
| 47 | +DMsSampleSetupStack.cdcTask2 = arn:aws:dms:us-east-1:000000000000:task:GO5RC4J6CKZWSJKF4CGB6ZV3ZEMGI38DFPJF2ZU |
| 48 | +DMsSampleSetupStack.cdcTaskSecret = arn:aws:secretsmanager:us-east-1:000000000000:secret:DMsSampleSetupStack-rdsinstanceSecret07FEB42-907ed0cf-RSPkZq |
| 49 | +DMsSampleSetupStack.fullTask1 = arn:aws:dms:us-east-1:000000000000:task:BCZLANJP9WFXKNTYBEWTAQ1YHIVJ5C2ZUIHDPB2 |
| 50 | +DMsSampleSetupStack.fullTask2 = arn:aws:dms:us-east-1:000000000000:task:ZO7WPZTTAKOA1CONK2Y3Y0H6FXLAFWUYX1OPGPM |
| 51 | +DMsSampleSetupStack.fullTaskSecret = arn:aws:secretsmanager:us-east-1:000000000000:secret:DMsSampleSetupStack-mariadbaccesssecret40AD7-611fcbcd-IKWDDh |
| 52 | +DMsSampleSetupStack.kinesisStream = arn:aws:kinesis:us-east-1:000000000000:stream/DMsSampleSetupStack-TargetStream3B4B2880-02dd0371 |
| 53 | +Stack ARN: |
| 54 | +arn:aws:cloudformation:us-east-1:000000000000:stack/DMsSampleSetupStack/b8298866 |
| 55 | + |
| 56 | +✨ Total time: 49.33s |
| 57 | +``` |
| 58 | + |
| 59 | +### Running the tasks |
| 60 | + |
| 61 | +You can run the tasks by executing the following command: |
| 62 | + |
| 63 | +```bash |
| 64 | +make run |
| 65 | +``` |
| 66 | + |
| 67 | +## Developer Notes |
| 68 | + |
| 69 | +Four tasks are deployed with the stack, split into two parts. |
| 70 | + |
| 71 | +First, a full load replication task runs against the external DB: |
| 72 | + |
| 73 | +- Creates three tables: `authors`, `accounts`, `novels` |
| 74 | +- Makes four inserts |
| 75 | +- Starts full load task 1 targeting tables starting with 'a' (`a%` table mapping) |
| 76 | +- Captures and logs six Kinesis events: 2 drop tables, 2 create tables, 2 inserts |
| 77 | +- Starts full load task 2 targeting the `novels` table (`novels` table mapping) |
| 78 | +- Captures and logs four Kinesis events: 1 drop table, 1 create table, 2 inserts |
| 79 | +- Logs `table_statistics` for both tasks |
| 80 | + |
| 81 | +Next, a CDC replication task runs against the RDS database: |
| 82 | + |
| 83 | +- Creates three tables: `authors`, `accounts`, `novels` |
| 84 | +- Starts CDC task 1 targeting tables starting with 'a' (`a%` table mapping) |
| 85 | +- Starts CDC task 2 targeting the `novels` table (`novels` table mapping) |
| 86 | +- Captures and logs five Kinesis events: 2 for `awsdms_apply_exceptions` table, 3 for our tables |
| 87 | +- Makes four inserts |
| 88 | +- Captures and logs four Kinesis events: 2 for tables in task 1, 2 for table in task 2 |
| 89 | +- Makes three table alterations, one per table |
| 90 | +- Captures and logs three Kinesis events |
| 91 | +- Logs `table_statistics` for both tasks |
| 92 | + |
| 93 | +Two tasks perform full load replication on Dockerized MariaDB. The other two perform CDC replication on a MariaDB RDS database. |
| 94 | + |
| 95 | +All tasks target the same Kinesis Stream. |
| 96 | + |
| 97 | +## Deploying on AWS |
| 98 | + |
| 99 | +You can deploy and run the stack on AWS by running the following commands: |
| 100 | + |
| 101 | +```bash |
| 102 | +make deploy-aws |
| 103 | +make run-aws |
| 104 | +``` |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +This project is licensed under the Apache 2.0 License. |
0 commit comments