<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Leonid Gimelshtein</title>
    <description>The latest articles on DEV Community by Leonid Gimelshtein (@lgimelshtein).</description>
    <link>https://dev.to/lgimelshtein</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1143340%2F0928cc97-c403-4d16-8b88-760ab9511ee7.png</url>
      <title>DEV Community: Leonid Gimelshtein</title>
      <link>https://dev.to/lgimelshtein</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lgimelshtein"/>
    <language>en</language>
    <item>
      <title>Utilizing SSM Documents for Seamless Tunneling to RDS</title>
      <dc:creator>Leonid Gimelshtein</dc:creator>
      <pubDate>Thu, 26 Oct 2023 14:46:41 +0000</pubDate>
      <link>https://dev.to/aws-builders/utilizing-ssm-documents-for-seamless-tunneling-to-rds-24h2</link>
      <guid>https://dev.to/aws-builders/utilizing-ssm-documents-for-seamless-tunneling-to-rds-24h2</guid>
      <description>&lt;p&gt;When deploying application servers or databases within private subnets following best security practices, it is essential to establish a robust system for resource management and access. This ensures efficient resource management and facilitates effective troubleshooting when necessary. How can you securely access it by creating tunnelling using an SSM document?&lt;/p&gt;

&lt;p&gt;Why go with this approach and tunnel through a bastion host? The key advantage is that SSM records all connections in CloudWatch for audit and security; plus, it's an additional way to connect to private resources.&lt;/p&gt;

&lt;p&gt;This solution enables the creation of a tunnel to access other private resources, such as EC2 instances and RDS.&lt;br&gt;
In this blog post, I will show how to create tunnelling to RDS or any EC2 resources within that private subnet while maintaining security using the SSM document.&lt;br&gt;
This is a short step-by-step guide to help you establish a secure connection to your RDS instance.&lt;br&gt;
By the end of this article, you'll clearly understand how to access your RDS instance using SSM documents, keeping your network safe. All the connections established via SSM are recorded in CloudWatch for audit and security purposes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-Requirements:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I assume you've already set up a Bastion host in your public subnet so that the host can establish communication with the RDS instance, and your public IP is whitelisted and has access to the Bastion host. We'll rely on the &lt;strong&gt;AWS-StartPortForwardingSessionToRemoteHost&lt;/strong&gt; SSM document for tunnelling purposes.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To perform this task, you should have the AWS CLI installed and configured on your machine and the necessary permissions granted to your IAM user.&lt;br&gt;
** We are ready to go ... **&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step 1: in your host file &lt;strong&gt;/etc/hosts&lt;/strong&gt;, add the record for the RDS endpoint we will use later to access using the database client to connect to the RDS instance&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;localhost &amp;lt;rds-endpoint&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step2: Run the following command to create a tunnel
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;aws --profile &amp;lt;aws_profile&amp;gt; ssm start-session --target &amp;lt;bastion-host-ec2-id&amp;gt; --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host=&amp;lt;rds-endpoint-name&amp;gt;,portNumber=5432,localPortNumber=5433 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait until the connection is established; you can connect to the database using the below command or use your favourite DB management tool, PGAdmin or MySQLWorkbench if it is MySQL Database.&lt;br&gt;
Here is the screenshot from Session Manager:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4iKaGFtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ng9dugjs6w3xgkm7wuq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4iKaGFtD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ng9dugjs6w3xgkm7wuq.png" alt="Image description" width="800" height="162"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step3: Connect using psql cli
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;psql -h 127.0.0.1 -p 5433 -U postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4mqvbw5H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahn31lqfpn3wcopc6bcq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4mqvbw5H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ahn31lqfpn3wcopc6bcq.png" alt="Session" width="638" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>aws</category>
      <category>devops</category>
      <category>database</category>
      <category>security</category>
    </item>
    <item>
      <title>Migrating MSSQL to AWS using Data Migration Service with CDC Migration</title>
      <dc:creator>Leonid Gimelshtein</dc:creator>
      <pubDate>Wed, 06 Sep 2023 19:39:55 +0000</pubDate>
      <link>https://dev.to/aws-builders/migrating-mssql-to-aws-using-data-migration-service-with-cdc-migration-4n85</link>
      <guid>https://dev.to/aws-builders/migrating-mssql-to-aws-using-data-migration-service-with-cdc-migration-4n85</guid>
      <description>&lt;h2&gt;
  
  
  Overview and Objectives
&lt;/h2&gt;

&lt;p&gt;The objective of this guide is to outline a comprehensive approach to migrating a Microsoft SQL Server database that is hosted on-premises to Amazon Web Services (AWS) using the AWS Database Migration Service (DMS). This document provides a step-by-step guide covering all important aspects of the migration process, including the setup of the DMS infrastructure, creation of endpoints, replication tasks, monitoring, and configuration of the source MSSQL database, and the destination database.&lt;br&gt;
In line with AWS recommended practices, the DMS instance will be deployed within a private subnet. The connection between the on-premises source and AWS will be established through a VPN connection, which will not be addressed in this article. As an alternative, in instances where VPN is not set up, the DMS can be deployed within a public subnet with restricted access through a security group attached to it. Access will be granted only from a designated source IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The business benefits of this migration include:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Zero Downtime: With this migration process, you can move any MSSQL servers from on-premises or from other hosting providers, such as Azure or GCP, to AWS RDS with no interruption to your operations.&lt;br&gt;
Reproducible Setup: By using the same setup for all customers, you can reduce the variations in deployment and improve knowledge management, reducing the risk of errors.&lt;/p&gt;
&lt;h2&gt;
  
  
  High-Level Solution Design
&lt;/h2&gt;

&lt;p&gt;The following sections will outline the components included in the offering, provide a high-level overview of the architecture, and present a detailed plan for constructing the solution.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48qc28o6pnbiq32rlcks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F48qc28o6pnbiq32rlcks.png" alt="Migration Diagram"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Networking Setup and DMS Replication instance setup
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;VPC Networking Setup&lt;/strong&gt;&lt;br&gt;
The following prerequisites for setting up a DMS migration must include all essential network components to ensure the product's viability as a turn-key solution for the migration process. These components are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Virtual Private Cloud (VPC) to host the destination MSSQL RDS instance.&lt;/li&gt;
&lt;li&gt;Three-tiered Subnets - frontend (public), Database and DMS replication instance (private network with internet access through a NAT gateway), Data layer (internal network without internet access for managed services such as RDS, VPC endpoints, etc.)&lt;/li&gt;
&lt;li&gt;Setting up VPC Endpoints for RDS, S3, and Cloudwatch,with the capability to add or remove endpoints per customer deployment, is a recommended best practice, especially when using the DMS instance version 3.4.7 This allows for flexibility in case additional services are required in the future.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  DMS and RDS Replication Instance Setup
&lt;/h2&gt;

&lt;p&gt;Before starting the migration, it's important to set up the MSSQL RDS instances properly, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MSSQL RDS Instance&lt;/li&gt;
&lt;li&gt;Security Groups (one for the Database Listener for the RDS and another for the DMS security group)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DMS Replication Instance using console or automation option.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS RDS target instance nodes - with pre-set recommendations for the appropriate instance type based on the workload.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When selecting the instance type, several factors should be taken into consideration, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The environment's lifecycle (development, QA, production)&lt;/li&gt;
&lt;li&gt;The workloads running on the instance, including memory, CPU, and network requirements&lt;/li&gt;
&lt;li&gt;Storage allocation to ensure the ability to migrate and host the production databases.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcnltk31w7cvx9d53xmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwcnltk31w7cvx9d53xmw.png" alt="DMS Instance"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Pre-Migration configuration steps on the MSSQL source instance
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pre-requirements:&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
To enable Transactional Replication and CDC for tables without primary keys via the DMS source endpoint, sysadmin permission must be granted to the &lt;em&gt;dms_user&lt;/em&gt;. This can be accomplished by adding the "&lt;em&gt;setUpMsCdcForTables=true&lt;/em&gt;" flag as an extra connection attribute to the source connection endpoint in DMS version 3.4.7, which is a new and available feature that has been released for version 3.4.7.&lt;/p&gt;

&lt;p&gt;If you would like to perform the setup manually the steps below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;dms_user&lt;/em&gt; will be created for use in the DMS source endpoint and will be granted the necessary &lt;a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html" rel="noopener noreferrer"&gt;permissions.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enable Transactional Replication on the instance for tables with primary &lt;a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html" rel="noopener noreferrer"&gt;keys&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Enable CDC on the source database use:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use [source_db_name] EXEC sys.sp_cdc_enable_db;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Next, set-up MS-CDC for each of the source tables. For each table with unique keys but no primary key, run the following query to set up MS-CDC.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exec sys.sp_cdc_enable_tabl
@source_schema = N'schema_name',
@source_name = N'table_name',
@index_name = N'unique_index_name',
@role_name = NULL,
@supports_net_changes = 1
GO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;For each table with no primary key or no unique keys, run the following query to set up MS-CDC.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exec sys.sp_cdc_enable_tabl
@source_schema = N'schema_name',
@source_name = N'table_name',
@role_name = NULL
GO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;Pre-migration process steps&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
To minimize migration downtime, the following task needs to be performed on the source database:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A full backup must be taken of the source database, which must be using either the Bulk-Logged or Full recovery model.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BACKUP DATABASE &amp;lt;database_name&amp;gt; TO DISK = 'D:\Backups\database_name_datetime.bak
WITH NOFORMAT, NOINIT, NAME = 'database_name_datetime',
SKIP, NOREWIND, NOUNLOAD, STATS = 10 GO
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;For the ongoing replication we need to capture the LSN number that will be used for the DMS replication task, take a record of the LSN
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select top 1 [Current LSN
from sys.fn_dump_dblog (NULL, NULL,NULL, 1,'C:\Backups\BackupDB\databasename_datetime.bak',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)
where operation='LOP_BEGIN_XACT'
and [Begin Time]&amp;gt;= cast('yyyy-mm-ddTMM:SS:ms' as datetime); –-&amp;lt; Datetime of the backup completed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is the example of the output of the query above:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8g882dm3d76stxeobn0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh8g882dm3d76stxeobn0.png" alt="LSN"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upload the backup files of the database to an S3 bucket for restoring the RDS instance at the destination. Before uploading, it's necessary to have access to the S3 via the AWS Console or CLI. This requires that the AWS CLI and the IAM user's credentials have access to the S3 bucket.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; aws s3 cp database_name_datetime.bak s3://&amp;lt;s3-bucket-name&amp;gt;/database_name_datetime.bak
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Restore backup from S3 bucket on RDS instance
&lt;/h2&gt;

&lt;p&gt;Create IAM Role and manage or inline policy:&lt;br&gt;
&lt;em&gt;Trusted entities:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "Version": "2012-10-17",

    "Statement": [

        {
            "Sid": "",
            "Effect": "Allow",
            "Principal": {
                "Service": "rds.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Custom managed or inline policy:&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "kms:DescribeKey",
                "kms:GenerateDataKey",
                "kms:Encrypt",
                "kms:Decrypt"
            ],
            "Resource": "arn:aws:kms:us-east-1:&amp;lt;aws_account_id&amp;gt;:key/&amp;lt;kms_key_id&amp;gt;"
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::s3-example-dmsupload",
                "arn:aws:s3:::s3-example-mssql-audit-logs"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:ListMultipartUploadParts",
                "s3:AbortMultipartUpload"
            ],
            "Resource": [
                "arn:aws:s3:::s3-example-dmsupload/*",
                "arn:aws:s3:::s3-example-mssql-audit-logs/*"
            ]
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To restore the database from an S3 bucket on RDS, it is necessary to have the &lt;em&gt;SQLSERVER_BACKUP_RESTORE&lt;/em&gt; option pre-configured in the option group and an IAM role was created, as shown in the screenshots below:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To access the MSSQL option group created during RDS setup in the AWS console, go to RDS and click on "Option Groups" on the left-hand side. Then, add the value and IAM role, and apply the changes to the RDS instance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqkm6xy999lm5v00k2qo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuqkm6xy999lm5v00k2qo.png" alt="RDS Option Groups"&gt;&lt;/a&gt;&lt;br&gt;
Example of the ARN:&lt;code&gt;arn:aws:iam::&amp;lt;aws_account_id&amp;gt;: role/&amp;lt;role_name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvebehjcw5liza12o95q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvebehjcw5liza12o95q.png" alt="ARN"&gt;&lt;/a&gt;&lt;br&gt;
The &lt;em&gt;SQLSERVER_BACKUP_RESTORE&lt;/em&gt; option should have the correct IAM role and policy that grants access to the S3 bucket containing the database backup files.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Restore the database on the RDS instance
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exec  msdb.dbo.rds_restore_database
    @restore_db_name='&amp;lt;DatabaseName&amp;gt;', 
    @s3_arn_to_restore_from='arn:aws:s3:::&amp;lt;s3_bucket_name&amp;gt;/databasename_datetime.bak',
    @with_norecovery=0,
    @type='FULL';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check the status of the restore process &lt;code&gt;exec msdb.dbo.rds_task_status;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run the following command on the source database to enable CDC.&lt;br&gt;
&lt;code&gt;use [DatabaseName]&lt;br&gt;
EXEC sys.sp_cdc_enable_db&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Disable Triggers on the destination RDS database schema&lt;br&gt;
&lt;code&gt;DISABLE TRIGGER ALL ON [destanation_db_name]&lt;br&gt;
EXEC sp_MSforeachtable "ALTER TABLE ? DISABLE TRIGGER all"&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Disable constraints on the target database&lt;br&gt;
&lt;code&gt;EXEC sp_MSforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
At last, we are prepared to set up the replication task. Ensure that the necessary DMS instance has been deployed and that all the security access required between the source and destination has been configured&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create Target and Source Endpoints
&lt;/h2&gt;

&lt;p&gt;Create Source and Target endpoints used by the migration task per database in the AWS account. &lt;br&gt;
This step is done with the following pre-requisite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The DMS instance has been deployed.&lt;/li&gt;
&lt;li&gt;The network connectivity/security for the DMS and RDS instance is configured between the source and destination.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The task can be created as a part of the DMS creation via console or automation using Terraform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of the source endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwjcs1z3ymowepxs6byt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwjcs1z3ymowepxs6byt.png" alt="Source Endpoint"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Example of the target endpoint&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bs1korusujs897v6czd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bs1korusujs897v6czd.png" alt="Target Endpoint"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create DMS migration type ongoing replication
&lt;/h2&gt;

&lt;p&gt;The task can be created manually or via automation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuwydj92xzin167duaem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxuwydj92xzin167duaem.png" alt="Ongoing Replication Task"&gt;&lt;/a&gt;&lt;br&gt;
When you create a task please use the following options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select "Enable custom CDC start mode"&lt;/li&gt;
&lt;li&gt;Specify a log sequence number ( The LSN was recorded during the performance of the source backup.)&lt;/li&gt;
&lt;li&gt;Target table preparation mode "Do nothing"&lt;/li&gt;
&lt;li&gt;Include LOB columns in replication "Full LOB mode"&lt;/li&gt;
&lt;li&gt;LOB chunk size (kb) = 64 This is for the LOB&lt;/li&gt;
&lt;li&gt;Task logs = True&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flsseze26fqi02s4vjyvk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flsseze26fqi02s4vjyvk.png" alt="Task Settings LSN"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvehw9orbzwn1rxcj5aex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvehw9orbzwn1rxcj5aex.png" alt="Full LOB"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5pwfsv7emvzrxb1p3qj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5pwfsv7emvzrxb1p3qj.png" alt="Task Setting Lob value"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbf6i4wnnfpnnayg7v4sv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbf6i4wnnfpnnayg7v4sv.png" alt="Task Settings Logs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi81nde3u0usv5m2q38o3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi81nde3u0usv5m2q38o3.png" alt="Task Advance Settings"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozuz9umfuaov300sxi58.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozuz9umfuaov300sxi58.png" alt="Task Setting Mapping"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the task is created, it's time to kick it off! The DMS task will automatically enable transactional replication and change data capture (CDC) on the source database. To keep an eye on its progress, take a look at the stats tab within the task and monitor the CloudWatch logs for any error messages.&lt;br&gt;
&lt;em&gt;Tip:&lt;/em&gt; In order to minimize IO and high CPU usage on the source instance and reduce the delta, it is advisable to use the latest backup from the source for CDC replication, which can help to lower the amount of transaction log reads required from the source database.&lt;br&gt;
&lt;em&gt;Tip:&lt;/em&gt; For managing large tables, it is advisable to create individual DMS tasks for each table.&lt;br&gt;
&lt;em&gt;Tip:&lt;/em&gt; To monitor DMS tasks, you can use CloudWatch to check the DMS instance and task statistics.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/database/new-features-in-aws-dms-3-4-7" rel="noopener noreferrer"&gt;DMS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html#CHAP_Source.SQLServer.DataTypes" rel="noopener noreferrer"&gt;DATATYPES&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Troubleshooting.html#CHAP_Troubleshooting.Oracle.LOBChanges" rel="noopener noreferrer"&gt;LOB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/dms/latest/userguide/CHAP_Source.SQLServer.html" rel="noopener noreferrer"&gt;SOURCE&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>awsbigdata</category>
      <category>devops</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
