Amazon DynamoDB Sink Connector for Confluent Cloud

The Kafka Connect Amazon DynamoDB Sink connector for Confluent Cloud is used to export messages from Apache Kafka® to Amazon DynamoDB, allowing you to export your Kafka data into your DynamoDB key-value and document database.

The connector periodically polls data from Kafka and writes it to Amazon DynamoDB. The data from each Kafka topic is batched and sent to DynamoDB. Because of constraints from DynamoDB, each batch can only contain one change per key, and each failure in a batch must be handled before the next batch is processed. These constraints ensure exactly once delivery. When a table doesn’t exist, the connector creates the table dynamically (depending on the connector configuration and permissions).

Important

If you are still on Confluent Cloud Enterprise, please contact your Confluent Account Executive for more information about using this connector.

Features

  • Auto-created tables: Tables can be auto-created based on topic names and auto-evolved based on the record schema.
  • Select configuration properties:
    • aws.dynamodb.pk.hash: Defines how the DynamoDB table hash key is extracted from the records. By default, the Kafka partition number where the record is generated is used as the hash key. Other record references can be used to create the hash key. See DynamDB hash keys and sort keys for examples.
    • aws.dynamodb.pk.sort: Defines how the DynamoDB table sort key is extracted from the records. By default, the record offset is used as the sort key. The sort key can be created from other references. See DynamDB hash keys and sort keys for examples.

See Configuration Properties for configuration property values and descriptions. See Cloud connector limitations for additional information.

DynamDB hash keys and sort keys

The following examples show how the aws.dynamodb.pk.hash and aws.dynamodb.pk.sort are used. The following Avro record is used for the examples:

{
     "ordertime": 1511538140542,
     "orderid": 3243,
     "itemid": "Item_117",
     "orderunits": 1.135368875862714,
     "address": {
       "city": "City_43",
       "state": "State_53",
     }
}

Example 1

The table hash key is set to the "partition" number where the record was generated. The table sort key is the record "offset". The following example uses these default configuration properties:

  • "aws.dynamodb.pk.hash":"partition"
  • "aws.dynamodb.pk.sort":"offset"

Using these properties, the table in DynamoDB would be similar to the following example:

partition offset address itemid orderid ordertime orderunits
0 6075 {“city”:{“S”:City_66}, “state”:{“S”:”State_42},…} Item_246 6075 1503153618445 3.0818679447783652
0 6076 {“city”:{“S”:City_38}, “state”:{“S”:”State_49},…} Item_536 6076 1515872966736 1.6264301342871472
0 6077 {“city”:{“S”:City_32}, “state”:{“S”:”State_62},…} Item_997 6077 1515872966736 4.189731783402986

Example 2

The table hash key is set to "value.orderid". The table sort key is "". Note that in this example, no sort key is required so you can use an empty string: "aws.dynamodb.pk.sort":"".

  • "aws.dynamodb.pk.hash":"value.orderid"
  • "aws.dynamodb.pk.sort":""

Using these properties, the table in DynamDB would be similar to the following example:

orderid address itemid ordertime orderunits
2007 {“city”:{“S”:City_69}, “state”:{“S”:”State_19},…} Item_809 1502071602628 8.9866703527786968
2011 {“city”:{“S”:City_32}, “state”:{“S”:”State_11},…} Item_524 1494848995282 2.581428966318308
2012 {“city”:{“S”:City_88}, “state”:{“S”:”State_94},…} Item_169 1491811930181 1.5716303109073455

Example 3

The table hash key is set to "value.orderid". The table sort key is set to "value.ordertime". Note that in this example, one of the record fields ("ordertime") is used as the sort key.

  • "aws.dynamodb.pk.hash":"value.orderid"
  • "aws.dynamodb.pk.sort":"value.ordertime"

Using these properties, the table in DynamoDB would be similar to the following example:

orderid ordertime address itemid orderunits
4520 1519049522647 {“city”:{“S”:City_99}, “state”:{“S”:”State_38},…} Item_650 7.658775648983428
4522 1519049522647 {“city”:{“S”:City_72}, “state”:{“S”:”State_89},…} Item_503 2.1383312466612261
4523 1507101063792 {“city”:{“S”:City_74}, “state”:{“S”:”State_99},…} Item_369 2.1383312466612261

Managing Throughput

When the connector creates a table automatically, 10 write capacity units are provisioned. If the connector needs to send records faster than the provisioned capacity, you may see the following error message:

Hit provisioning capacity, will retry indefinitely.. Increase your throughput capacity

You can increase the write capacity or use Amazon DynamoDB Auto Scaling.

Quick Start

Use this quick start to get up and running with the Confluent Cloud Amazon DynamoDB Sink connector. The quick start provides the basics of selecting the connector and configuring it to stream events to Amazon Redshift.

Prerequisites
  • Kafka cluster credentials. You can use one of the following ways to get credentials:
    • Create a Confluent Cloud API key and secret. To create a key and secret, you can use the Confluent Cloud CLI or you can autogenerate the API key and secret directly in the Cloud Console when setting up the connector.
    • Create a Confluent Cloud service account for the connector. Make sure to review the ACL entries required in the service account documentation. Some connectors have specific ACL requirements.

Using the Confluent Cloud Console

Step 1: Launch your Confluent Cloud cluster.

See the Quick Start for Apache Kafka using Confluent Cloud for installation instructions.

Step 2: Add a connector.

In the left navigation menu, click Data integration, and then click Connectors. If you already have connectors in your cluster, click + Add connector.

Step 3: Select your connector.

Click the Amazon DynamoDB Sink connector icon.

Amazon DynamoDB Sink Connector Icon

Step 4: Set up the connection.

Note

  • Make sure you have all your prerequisites completed.
  • An asterisk ( * ) designates a required entry.

Complete the following and click Continue.

  1. Select one or more topics.
  2. Enter a Connector Name.
  3. Select an Input message format (data coming from the Kafka topic): AVRO, JSON_SR (JSON Schema), PROTOBUF, or JSON. A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).
  4. Enter your Kafka Cluster credentials. The credentials are either the API key and secret or the service account API key and secret.
  5. Enter your AWS credentials.
  6. Enter your hash key and sort key. By default, the Kafka partition number is used for the hash key and the record offset is used as the sort key. For a few examples of how these keys work with other record references, see DynamDB hash keys and sort keys. Note that the maximum size of a partition using the default configuration is limited to 10 GB (defined by Amazon DynamoDB).
  7. Providing a Table name format is optional and defaults to the name of the Kafka topic. To create a table name format use the syntax ${topic}. For example, kafka_${topic} for the topic orders maps to the table name kafka_orders.
  8. Enter the number of tasks for the connector. More tasks may improve performance.
  9. Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.

See Configuration Properties for configuration property values and descriptions.

Step 5: Launch the connector.

Verify the connection details and click Launch.

Step 6: Check the connector status.

The status for the connector should go from Provisioning to Running.

Step 7: Check the results in DynamoDB.

Check to verify that the database is being populated.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Tip

When you launch a connector, a Dead Letter Queue topic is automatically created. See Dead Letter Queue for details.

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

../_images/topology.png

Using the Confluent Cloud CLI

Complete the following steps to set up and run the connector using the Confluent Cloud CLI.

Note

Make sure you have all your prerequisites completed.

Step 1: List the available connectors.

Enter the following command to list available connectors:

ccloud connector-catalog list

Step 2: Show the required connector configuration properties.

Enter the following command to show the required connector properties:

ccloud connector-catalog describe <connector-catalog-name>

For example:

ccloud connector-catalog describe DynamoDbSink

Example output:

Following are the required configs:
connector.class: DynamoDbSink
input.data.format
name
kafka.api.key
kafka.api.secret
aws.access.key.id
aws.secret.access.key
tasks.max
topics

Step 3: Create the connector configuration file.

Create a JSON file that contains the connector configuration properties. The following example shows required and optional connector properties.

{
  "name": "DynamoDbSinkConnector_0",
  "config": {
    "topics": "pageviews",
    "input.data.format": "AVRO",
    "connector.class": "DynamoDbSink",
    "name": "DynamoDbSinkConnector_0",
    "kafka.api.key": "****************",
    "kafka.api.secret": "************************************************",
    "aws.access.key.id": "********************",
    "aws.secret.access.key": "****************************************",
    "aws.dynamodb.pk.hash": "value.userid",
    "aws.dynamodb.pk.sort": "value.pageid",
    "table.name.format": "kafka-${topic}",
    "tasks.max": "1"
  }
}

Note the following property definitions:

  • "name": Sets a name for your new connector.
  • "connector.class": Identifies the connector plugin name.
  • "topics": Identifies the topic name or a comma-separated list of topic names.
  • "input.data.format": Sets the input message format (data coming from the Kafka topic). Valid entries are AVRO, JSON_SR, PROTOBUF, or JSON. You must have Confluent Cloud Schema Registry configured if using a schema-based message format (for example, Avro, JSON_SR (JSON Schema), or Protobuf).
  • "aws.dynamodb.pk.hash": Defines how the DynamoDB table hash key is extracted from the records. By default, the Kafka partition number where the record is generated is used as the hash key. The hash key can be created from other record references. See DynamDB hash keys and sort keys for examples. Note that the maximum size of a partition using the default configuration is limited to 10 GB (defined by Amazon DynamoDB).
  • "aws.dynamodb.pk.sort": Defines how the DynamoDB table sort key is extracted from the records. By default, the record offset is used as the sort key. If no sort key is required, use an empty string for this property "". The sort key can be created from other record references. See DynamDB hash keys and sort keys for examples.
  • "table.name.format": The property is optional and defaults to the name of the Kafka topic. To create a table name format use the syntax ${topic}. For example, kafka_${topic} for the topic orders maps to the table name kafka_orders.
  • "tasks.max": Maximum number of tasks the connector can run. See Confluent Cloud connector limitations for additional task information.

Single Message Transforms: See the Single Message Transforms (SMT) documentation for details about adding SMTs using the CLI.

See Configuration Properties for configuration property values and descriptions.

Step 4: Load the configuration file and create the connector.

Enter the following command to load the configuration and start the connector:

ccloud connector create --config <file-name>.json

For example:

ccloud connector create --config dynamodb-sink-config.json

Example output:

Created connector DynamoDbSinkConnector_0 lcc-ix4dl

Step 5: Check the connector status.

Enter the following command to check the connector status:

ccloud connector list

Example output:

ID          |       Name              | Status  | Type
+-----------+-------------------------+---------+------+
lcc-ix4dl   | DynamoDbSinkConnector_0 | RUNNING | sink

Step 6: Check the results in Redshift.

Check to verify that the database is being populated.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.

Tip

When you launch a connector, a Dead Letter Queue topic is automatically created. See Dead Letter Queue for details.

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

../_images/topology.png

Configuration Properties

The following connector configuration properties are used for the Amazon DynamoDB Sink connector for Confluent Cloud.

aws.dynamodb.pk.hash

Defines how the table’s hash key is extracted from the records. By default, partition is used as the hash key. The maximum size of a partition with this configuration is 10 GB as defined by DynamoDB limits.

This hash key reference is created from a record reference and optional alias name. If the alias name is absent, then the last field of the reference is used as the column name.

  • Type: string
  • Default: partition
  • Valid Values: Matches regex:
^(?<reference>partition|offset|key(\.[a-zA-Z1-9\_\-\.]{1,255})*|value(\.
[a-zA-Z1-9\_\-\.]{1,255})*){1}(:(?<alias>[a-zA-Z1-9\_\-\.]{1,255}))?$
  • Importance: high

See DynamDB hash keys and sort keys for examples.

The following are valid record references:

  • partition: The Kafka partition number where the record originated.
  • offset: The Kafka record offset.
  • key.[fieldNameOrDotDelimitedPath]: The record key or one of the fields from the record key.
  • value.[fieldNameOrDotDelimitedPath]: The record value or one of the fields from the record value.
aws.dynamodb.pk.sort

Defines how the table’s sort key is extracted from the records. By default, it uses the record offset as sort key. This sort key reference is created from a record reference and an optional alias name. If the alias name is absent, then the last field of the record reference is used as the column name. If no sort key is required, configure this property to be an empty string.

  • Type: string
  • Default: offset
  • Valid Values: Matches regex:
^(?<reference>partition|offset|key(\.[a-zA-Z1-9\_\-\.]{1,255})*|value(\.
[a-zA-Z1-9\_\-\.]{1,255})*){1}(:(?<alias>[a-zA-Z1-9\_\-\.]{1,255}))?$
or an empty string
  • Importance: high

See DynamDB hash keys and sort keys for examples.

The following are valid record references:

  • partition: The Kafka partition number where the record originated.
  • offset: The Kafka record offset.
  • key.[fieldNameOrDotDelimitedPath]: The record key or one of the fields from the record key.
  • value.[fieldNameOrDotDelimitedPath]: The record value or one of the fields from the record value.
table.name.format

A format string for the destination table name, which may contain ${topic} as a placeholder for the originating topic name. For example, kafka_${topic} for the topic orders maps to the table name kafka_orders.

  • Type: string
  • Default: ${topic}
  • Importance: medium

Next Steps

See also

For an example that shows fully-managed Confluent Cloud connectors in action with Confluent Cloud ksqlDB, see the Cloud ETL Demo. This example also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.

../_images/topology.png