A VPC associated with the ReplicationSubnetGroup does not exist error

Error

I was trying to create a replication instance in AWS Database Migration Service (DMS) using AWS CDK and received the following error.

A VPC associated with the Replication Subnet Group does not exist. Update the Replication Subnet Group and try again.

A VPC associated with the ReplicationSubnetGroup does not exist error

Code Snippet

CfnReplicationSubnetGroup cfnReplicationSubnetGroup = new CfnReplicationSubnetGroup(this, "MyCfnReplicationSubnetGroup", new CfnReplicationSubnetGroupProps {
    ReplicationSubnetGroupIdentifier = "DMS-SubnetGroupDemo",
        ReplicationSubnetGroupDescription = "ReplicationSubnetGroupDescription",
        SubnetIds = new [] {
            "subnet-a85ecae4",
            "subnet-93e3a5e9"
        }
});
CfnReplicationInstance cfndmsrepInstance = new CfnReplicationInstance(this, "MyReplicationInstance", new CfnReplicationInstanceProps {
    ReplicationInstanceClass = "dms.t3.large",
        ReplicationInstanceIdentifier = "ReplicationInstanceIdentifier",
        ReplicationSubnetGroupIdentifier = cfnReplicationSubnetGroup.ReplicationSubnetGroupIdentifier,
        VpcSecurityGroupIds = new [] {
            "sg-6dd89813"
        }
});
cfndmsrepInstance.AddDependsOn(cfnReplicationSubnetGroup);

Resolution

Even though you pass the replication subnet group identifier name with uppercase (DMS-SubnetGroupDemo), Cfn lowercases the ReplicationSubnetGroupIdentifier (dms-subnetgroupdemo) on creation as shown below but CDK passes the same string without lowercasing. This issue can be resolved by explicitly converting the ReplicationSubnetGroupIdentifier string to lowercase as shown in the below code snippet.

A VPC associated with the ReplicationSubnetGroup does not exist error

CfnReplicationSubnetGroup cfnReplicationSubnetGroup = new CfnReplicationSubnetGroup(this, "MyCfnReplicationSubnetGroup", new CfnReplicationSubnetGroupProps {
    ReplicationSubnetGroupIdentifier = "DMS-SubnetGroupDemo",
        ReplicationSubnetGroupDescription = "ReplicationSubnetGroupDescription",
        SubnetIds = new [] {
            "subnet-a85ecae4",
            "subnet-93e3a5e9"
        }
});
CfnReplicationInstance cfndmsrepInstance = new CfnReplicationInstance(this, "MyReplicationInstance", new CfnReplicationInstanceProps {
    ReplicationInstanceClass = "dms.t3.large",
        ReplicationInstanceIdentifier = "ReplicationInstanceIdentifier",
        ReplicationSubnetGroupIdentifier = cfnReplicationSubnetGroup.ReplicationSubnetGroupIdentifier.ToLower(),
        VpcSecurityGroupIds = new [] {
            "sg-6dd89813"
        }
});
cfndmsrepInstance.AddDependsOn(cfnReplicationSubnetGroup);

Reference

https://github.com/aws/aws-cdk/issues/11385