Amazon DynamoDB Sink Connector for Confluent Cloud¶
The fully-managed 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).
Note
- This Quick Start is for the fully-managed Confluent Cloud connector. If you are installing the connector locally for Confluent Platform, see Amazon DynamoDB Sink Connector for Confluent Platform.
- If you require private networking for fully-managed connectors, make sure to set up the proper networking beforehand. For more information, see Manage Networking for Confluent Cloud Connectors.
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 DynamoDB 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 DynamoDB hash keys and sort keys for examples.
For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Managed and Custom Connectors section.
Limitations¶
Be sure to review the following information.
- For connector limitations, see Amazon DynamoDB Sink Connector limitations.
- If you plan to use one or more Single Message Transforms (SMTs), see SMT Limitations.
- If you plan to use Confluent Cloud Schema Registry, see Schema Registry Enabled Environments.
DynamoDB IAM policy¶
Create an IAM user for the connector. Assign an IAM policy to the user you create. The policy must have the following minimum permissions.
- CreateTable
- BatchWriteItem
- Scan
- DescribeTable
You can copy the following JSON policy. For more information, see Creating policies on the JSON tab.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "<optional-identifier>",
"Effect": "Allow",
"Action": [
"dynamodb:CreateTable",
"dynamodb:BatchWriteItem",
"dynamodb:Scan",
"dynamodb:DescribeTable"
],
"Resource": "*"
}
]
}
DynamoDB 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 DynamoDB 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
- Authorized access to a Confluent Cloud cluster on Amazon Web Services.
- The Confluent CLI installed and configured for the cluster. See Install the Confluent CLI.
- Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf). See Schema Registry Enabled Environments for additional information.
- Authorized access to AWS and the Amazon DynamoDB database. For more information, see DynamoDB IAM policy.
- The database must be in the same region as your Confluent Cloud cluster.
- For networking considerations, see Networking and DNS. To use a set of public egress IP addresses, see Public Egress IP Addresses for Confluent Cloud Connectors.
- Kafka cluster credentials. The following lists the different ways you can provide credentials.
- Enter an existing service account resource ID.
- 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.
- Create a Confluent Cloud API key and secret. To create a key and secret, you can use confluent api-key create or you can autogenerate the API key and secret directly in the Cloud Console when setting up the connector.
Using the Confluent Cloud Console¶
Step 1: Launch your Confluent Cloud cluster¶
See the Quick Start for Confluent Cloud for installation instructions.
Step 2: Add a connector¶
In the left navigation menu, click Connectors. If you already have connectors in your cluster, click + Add connector.
Step 4: Enter the connector details¶
Note
- Ensure you have all your prerequisites completed.
- An asterisk ( * ) designates a required entry.
At the Add Amazon DynamoDB Sink Connector screen, complete the following:
If you’ve already populated your Kafka topics, select the topics you want to connect from the Topics list.
To create a new topic, click +Add new topic.
- Select the way you want to provide Kafka Cluster credentials. You can
choose one of the following options:
- My account: This setting allows your connector to globally access everything that you have access to. With a user account, the connector uses an API key and secret to access the Kafka cluster. This option is not recommended for production.
- Service account: This setting limits the access for your connector by using a service account. This option is recommended for production.
- Use an existing API key: This setting allows you to specify an API key and a secret pair. You can use an existing pair or create a new one. This method is not recommended for production environments.
- Click Continue.
- In the AWS access key ID field, enter the Amazon Access Key used to connect to Amazon DynamoDB.
- In the AWS secret access key field, enter the Amazon Secret Key used to connect to Amazon DynamoDB.
- Click Continue.
Note
Configuration properties that are not shown in the Cloud Console use the default values. See Configuration Properties for all property values and definitions.
Select the Input Kafka record value (data coming from the Kafka topic): AVRO, JSON_SR, PROTOBUF, or JSON. A valid schema must be available in Schema Registry to use a schema-based message format (for example, Avro, JSON Schema, or Protobuf). See Schema Registry Enabled Environments for additional information.
In the DynamoDB hash key and DynamoDB sort key fields, enter the hash key and sort key, respectively. 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 DynamoDB 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).
Show advanced configurations
Schema context: Select a schema context to use for this connector, if using a schema-based data format. This property defaults to the Default context, which configures the connector to use the default schema set up for Schema Registry in your Confluent Cloud environment. A schema context allows you to use separate schemas (like schema sub-registries) tied to topics in different Kafka clusters that share the same Schema Registry environment. For example, if you select a non-default context, a Source connector uses only that schema context to register a schema and a Sink connector uses only that schema context to read from. For more information about setting up a schema context, see What are schema contexts and when should you use them?.
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, to create a table namedkafka-orders
based on a Kafka topic namedorders
, you would enterkafka-${topic}
in this field.Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.
See Configuration Properties for all property values and definitions.
Click Continue.
Based on the number of topic partitions you select, you will be provided with a recommended number of tasks.
- To change the number of recommended tasks, enter the number of tasks for the connector to use in the Tasks field.
- Click Continue.
Verify the connection details.
Click Launch.
The status for the connector should go from Provisioning to Running.
Step 5: 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 Managed and Custom Connectors section.
Tip
When you launch a connector, a Dead Letter Queue topic is automatically created. See Confluent Cloud Dead Letter Queue for details.
Using the Confluent CLI¶
Complete the following steps to set up and run the connector using the Confluent CLI.
Note
Make sure you have all your prerequisites completed.
Step 1: List the available connectors¶
Enter the following command to list available connectors:
confluent connect plugin list
Step 2: List the connector configuration properties¶
Enter the following command to show the connector configuration properties:
confluent connect plugin describe <connector-plugin-name>
The command output shows the required and optional configuration properties.
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.auth.mode": "KAFKA_API_KEY",
"kafka.api.key": "<my-kafka-api-key>",
"kafka.api.secret": "<my-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.
"kafka.auth.mode"
: Identifies the connector authentication mode you want to use. There are two options:SERVICE_ACCOUNT
orKAFKA_API_KEY
(the default). To use an API key and secret, specify the configuration propertieskafka.api.key
andkafka.api.secret
, as shown in the example configuration (above). To use a service account, specify the Resource ID in the propertykafka.service.account.id=<service-account-resource-ID>
. To list the available service account resource IDs, use the following command:confluent iam service-account list
For example:
confluent iam service-account list Id | Resource ID | Name | Description +---------+-------------+-------------------+------------------- 123456 | sa-l1r23m | sa-1 | Service account 1 789101 | sa-l4d56p | sa-2 | Service account 2
"input.data.format"
: Sets the input Kafka record value 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 DynamoDB 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 DynamoDB 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 topicorders
maps to the table namekafka_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 Unsupported transformations for a list of SMTs that are not supported with this connector.
See Configuration Properties for all property values and definitions.
Step 4: Load the configuration file and create the connector¶
Enter the following command to load the configuration and start the connector:
confluent connect cluster create --config-file <file-name>.json
For example:
confluent connect cluster create --config-file 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:
confluent connect cluster 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 Managed and Custom Connectors section.
Tip
When you launch a connector, a Dead Letter Queue topic is automatically created. See Confluent Cloud Dead Letter Queue for details.
Configuration Properties¶
Use the following configuration properties with the fully-managed connector. For self-managed connector property definitions and other details, see the connector docs in Self-managed connectors for Confluent Platform.
Which topics do you want to get data from?¶
topics
Identifies the topic name or a comma-separated list of topic names.
- Type: list
- Importance: high
Schema Config¶
schema.context.name
Add a schema context name. A schema context represents an independent scope in Schema Registry. It is a separate sub-schema tied to topics in different Kafka clusters that share the same Schema Registry instance. If not used, the connector uses the default schema configured for Schema Registry in your Confluent Cloud environment.
- Type: string
- Default: default
- Importance: medium
Input messages¶
input.data.format
Sets the input Kafka record value format. Valid entries are AVRO, JSON_SR, PROTOBUF, or JSON. Note that you need to have Confluent Cloud Schema Registry configured if using a schema-based message format like AVRO, JSON_SR, and PROTOBUF.
- Type: string
- Default: JSON
- Importance: high
input.key.format
Sets the input Kafka record key format. Valid entries are AVRO, BYTES, JSON, JSON_SR, PROTOBUF, or STRING. Note that you need to have Confluent Cloud Schema Registry configured if using a schema-based message format like AVRO, JSON_SR, and PROTOBUF
- Type: string
- Default: BYTES
- Valid Values: AVRO, BYTES, JSON, JSON_SR, PROTOBUF, STRING
- Importance: high
How should we connect to your data?¶
name
Sets a name for your connector.
- Type: string
- Valid Values: A string at most 64 characters long
- Importance: high
Kafka Cluster credentials¶
kafka.auth.mode
Kafka Authentication mode. It can be one of KAFKA_API_KEY or SERVICE_ACCOUNT. It defaults to KAFKA_API_KEY mode.
- Type: string
- Default: KAFKA_API_KEY
- Valid Values: KAFKA_API_KEY, SERVICE_ACCOUNT
- Importance: high
kafka.api.key
Kafka API Key. Required when kafka.auth.mode==KAFKA_API_KEY.
- Type: password
- Importance: high
kafka.service.account.id
The Service Account that will be used to generate the API keys to communicate with Kafka Cluster.
- Type: string
- Importance: high
kafka.api.secret
Secret associated with Kafka API key. Required when kafka.auth.mode==KAFKA_API_KEY.
- Type: password
- Importance: high
AWS credentials¶
aws.access.key.id
- Type: password
- Importance: high
aws.secret.access.key
- Type: password
- Importance: high
DynamoDB Parameters¶
aws.dynamodb.pk.hash
- Type: string
- Default: partition
- Importance: high
aws.dynamodb.pk.sort
- Type: string
- Default: offset
- Importance: high
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’ will map to the table name ‘kafka_orders’.- Type: string
- Default: ${topic}
- Importance: medium
Consumer configuration¶
max.poll.interval.ms
The maximum delay between subsequent consume requests to Kafka. This configuration property may be used to improve the performance of the connector, if the connector cannot send records to the sink system. Defaults to 300000 milliseconds (5 minutes).
- Type: long
- Default: 300000 (5 minutes)
- Valid Values: [60000,…,1800000] for non-dedicated clusters and [60000,…] for dedicated clusters
- Importance: low
max.poll.records
The maximum number of records to consume from Kafka in a single request. This configuration property may be used to improve the performance of the connector, if the connector cannot send records to the sink system. Defaults to 500 records.
- Type: long
- Default: 500
- Valid Values: [1,…,500] for non-dedicated clusters and [1,…] for dedicated clusters
- Importance: low
Number of tasks for this connector¶
tasks.max
Maximum number of tasks for the connector.
- Type: int
- Valid Values: [1,…]
- Importance: high
Next Steps¶
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 CLI to manage your resources in Confluent Cloud.
Try Confluent Cloud on AWS Marketplace with $1000 of free usage for 30 days, and pay as you go. No credit card is required.