- Newest
- Most votes
- Most comments
When using AWS DMS to migrate data to a Kafka topic, you can customize the partition key to achieve your desired format of "XX-1234" where XX is your source identifier and 1234 is the primary key value.
The partition-key-type and partition-key-name approach won't directly give you the combined format you want. These settings would allow you to use either a specific attribute name as the partition key or a schema/table name, but not a combination with a constant value.
For your specific requirement, you would need to use attribute mapping to create a new attribute that combines your source identifier with the primary key value, and then use that attribute as your partition key. Here's how you could approach it:
- First, create an attribute mapping that combines your source identifier with the primary key:
"mapping-parameters": {
"attribute-mappings": [
{
"target-attribute-name": "custom_key",
"attribute-type": "scalar",
"attribute-sub-type": "string",
"value": "${pkfield}"
},
{
"target-attribute-name": "source",
"attribute-type": "scalar",
"attribute-sub-type": "string",
"value": "XX"
}
]
}
- Then use this new attribute as your partition key:
"partition-key-type": "attribute-name",
"partition-key-name": "custom_key"
Unfortunately, AWS DMS doesn't support string concatenation directly in the attribute mapping expressions, so you can't create "XX-${pkfield}" in a single step. The approach above will get you the primary key value as the partition key, but not with the "XX-" prefix combined in the way you want.
If having this exact format is critical, you might need to consider processing the messages after they arrive in Kafka to modify the keys, or explore if a custom transformation script within AWS DMS could help achieve this specific formatting requirement.
Sources
Using Apache Kafka as a target for AWS Database Migration Service - AWS Database Migration Service
Using Amazon Kinesis Data Streams as a target for AWS Database Migration Service - AWS Database Migration Service
KafkaSettings - AWS Database Migration Service
answered a year ago
DMS doesn’t support concatenating static strings with column values inside the partition-key or partition-key-name fields. The partition-key-type can only reference an existing column (attribute-name) or use a fixed constant (literal), but it can’t perform dynamic string interpolation such as "XX-${pkfieldvalue}". The kafka-target-key is automatically derived from the table’s primary key unless explicitly overridden, and any prefix or composite key logic must be handled before the record reaches Kafka.
If you need the Kafka message key to be XX-<pkvalue>, add a derived column in the mapping using map-record-to-record to build that value.
—Taz
answered a year ago
Relevant content
asked 2 years ago
asked 2 years ago
- AWS OFFICIALUpdated 4 years ago
