A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources with infrastructure-as-code.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
AWS Database Migration Service helps you migrate databases to AWS quickly and securely with minimal downtime.
import * as aws from "@pulumi/aws";
import * as dms from "@pulumi/aws/dms";DMS replication instance for running migration tasks.
const replicationInstance = new aws.dms.ReplicationInstance("dms-instance", {
replicationInstanceId: "my-dms-instance",
replicationInstanceClass: "dms.t3.medium",
allocatedStorage: 100,
vpcSecurityGroupIds: [securityGroup.id],
replicationSubnetGroupId: subnetGroup.id,
publiclyAccessible: false,
multiAz: true,
engineVersion: "3.4.7",
tags: {
Name: "DMS Replication Instance",
},
});Subnet group for the replication instance.
const subnetGroup = new aws.dms.ReplicationSubnetGroup("dms-subnet-group", {
replicationSubnetGroupId: "dms-subnet-group",
replicationSubnetGroupDescription: "DMS Replication Subnet Group",
subnetIds: subnetIds,
tags: {
Name: "DMS Subnet Group",
},
});Source database endpoint configuration.
const sourceEndpoint = new aws.dms.Endpoint("source", {
endpointId: "source-postgres",
endpointType: "source",
engineName: "postgres",
serverName: sourceDb.address,
port: 5432,
databaseName: "mydb",
username: "admin",
password: dbPassword,
sslMode: "require",
tags: {
Type: "source",
},
});Target database endpoint configuration.
const targetEndpoint = new aws.dms.Endpoint("target", {
endpointId: "target-postgres",
endpointType: "target",
engineName: "postgres",
serverName: targetDb.address,
port: 5432,
databaseName: "mydb",
username: "admin",
password: dbPassword,
sslMode: "require",
tags: {
Type: "target",
},
});Database replication task.
const replicationTask = new aws.dms.ReplicationTask("migration-task", {
replicationTaskId: "database-migration",
migrationType: "full-load-and-cdc",
replicationInstanceArn: replicationInstance.replicationInstanceArn,
sourceEndpointArn: sourceEndpoint.endpointArn,
targetEndpointArn: targetEndpoint.endpointArn,
tableMappings: JSON.stringify({
rules: [{
"rule-type": "selection",
"rule-id": "1",
"rule-name": "1",
"object-locator": {
"schema-name": "public",
"table-name": "%",
},
"rule-action": "include",
}],
}),
replicationTaskSettings: JSON.stringify({
TargetMetadata: {
TargetSchema: "",
SupportLobs: true,
FullLobMode: false,
LobChunkSize: 64,
LimitedSizeLobMode: true,
LobMaxSize: 32,
},
FullLoadSettings: {
TargetTablePrepMode: "DROP_AND_CREATE",
},
Logging: {
EnableLogging: true,
LogComponents: [{
Id: "TRANSFORMATION",
Severity: "LOGGER_SEVERITY_DEFAULT",
}],
},
}),
tags: {
Name: "Database Migration Task",
},
});const fullLoadTask = new aws.dms.ReplicationTask("full-load", {
replicationTaskId: "full-load-migration",
migrationType: "full-load",
replicationInstanceArn: replicationInstance.replicationInstanceArn,
sourceEndpointArn: sourceEndpoint.endpointArn,
targetEndpointArn: targetEndpoint.endpointArn,
tableMappings: JSON.stringify({
rules: [{
"rule-type": "selection",
"rule-id": "1",
"rule-name": "1",
"object-locator": {
"schema-name": "%",
"table-name": "%",
},
"rule-action": "include",
}],
}),
});const cdcTask = new aws.dms.ReplicationTask("cdc-only", {
replicationTaskId: "cdc-replication",
migrationType: "cdc",
cdcStartTime: "2024-01-01T00:00:00Z",
replicationInstanceArn: replicationInstance.replicationInstanceArn,
sourceEndpointArn: sourceEndpoint.endpointArn,
targetEndpointArn: targetEndpoint.endpointArn,
tableMappings: JSON.stringify({
rules: [{
"rule-type": "selection",
"rule-id": "1",
"rule-name": "1",
"object-locator": {
"schema-name": "public",
"table-name": "%",
},
"rule-action": "include",
}],
}),
});const s3Endpoint = new aws.dms.Endpoint("s3-target", {
endpointId: "target-s3",
endpointType: "target",
engineName: "s3",
s3Settings: {
bucketName: targetBucket.id,
bucketFolder: "dms-output",
compressionType: "GZIP",
dataFormat: "parquet",
serviceAccessRoleArn: dmsRole.arn,
},
});Monitor DMS events with SNS.
const eventSubscription = new aws.dms.EventSubscription("dms-events", {
name: "dms-event-subscription",
enabled: true,
eventCategories: [
"creation",
"failure",
"configuration change",
],
sourceType: "replication-task",
sourceIds: [replicationTask.replicationTaskId],
snsTopicArn: snsTopic.arn,
});replicationInstanceClass - Instance class (dms.t3.medium, etc.)allocatedStorage - Storage in GBmultiAz - Enable Multi-AZengineVersion - DMS engine versionpubliclyAccessible - Public access flagendpointType - Type (source or target)engineName - Database engineserverName - Database server hostnameport - Database portdatabaseName - Database namesslMode - SSL mode (none, require, verify-ca, verify-full)migrationType - Migration type (full-load, cdc, full-load-and-cdc)tableMappings - Selection and transformation rulesreplicationTaskSettings - Task settings JSONreplicationInstanceArn - Replication instance ARNendpointArn - Endpoint ARNreplicationTaskArn - Task ARNInstall with Tessl CLI
npx tessl i tessl/npm-pulumi--aws