AWS DMS 是用于在云之间将数据复制和转换到目标数据存储区域的服务。它不允许直接修改源表,这是为了确保数据完整性和源系统稳定性。如果您需要修改源表,应该使用源系统提供的机制或通过目标表的操作来代替。
以下是使用 AWS Lambda 和 AWS DMS 进行源表触碰和修改的示例代码:
1.使用 AWS Lambda 触发器连接 AWS DMS 进行表修改:
import boto3
import json
def lambda_handler(event, context):
client = boto3.client('dms')
response = client.modify_replication_task(
ReplicationTaskArn='arn:aws:dms:us-east-1:012345678910:task:example-task-1',
TableMappings='{"rules":[{"rule-type":"selection","rule-id":"1","rule-name":"1","object-locator":{"schema-name":"public","table-name":"source_table"},"rule-action":"include"}]}',
ReplicationTaskIdentifier='example-task-1',
MigrationType='full-load'
)
return {
'statusCode': 200,
'body': json.dumps('Table mappings modified successfully')
}
2.使用 AWS DMS 执行插入操作:
{
"type": "insert",
"schema-name": "public",
"table-name": "target_table",
"values": [
{
"id": "1",
"name": "example"
}
]
}