Amazon S3 Sink Connector for Confluent Cloud

Note

If you are installing the connector locally for Confluent Platform, see Amazon S3 Sink Connector for Confluent Platform.

You can use the Kafka Connect Amazon S3 sink connector to export data from Apache Kafka® topics to S3 objects in either Avro, JSON, or Bytes formats. Depending on your environment, the S3 connector can export data by guaranteeing exactly-once delivery semantics to consumers of the S3 objects it produces.

The Amazon S3 sink connector periodically polls data from Kafka and in turn uploads it to S3. A partitioner is used to split the data of every Kafka partition into chunks. Each chunk of data is represented as an S3 object. The key name encodes the topic, the Kafka partition, and the start offset of this data chunk. If no partitioner is specified in the configuration, the default partitioner which preserves Kafka partitioning is used. The size of each data chunk is determined by the number of records written to S3 and by schema compatibility.

Features

The Amazon S3 Sink connector for Confluent Cloud provides the following features:

  • Exactly Once Delivery: Records that are exported using a deterministic partitioner are delivered with exactly-once semantics regardless of the eventual consistency of S3.

  • Data Format with or without Schema: Out of the box, the connector supports writing data to S3 in Avro, JSON, and Bytes. Schema validation is disabled for JSON.

  • Schema Evolution: schema.compatibility is set to NONE.

  • Partitioner: The connector supports the TimeBasedPartitioner class based on the Kafka class TimeStamp. Time-based partitioning options are daily or hourly.

  • Flush size: flush.size defaults to 1000. The default value can be increased if needed.

    The following scenarios describe a couple of ways records may be flushed to storage:

    • You use the default setting of 1000 and your topic has six partitions. Files start to be created in storage after more than 1000 records exist in each partition.
    • You use the default setting of 1000 and the partitioner is set to Hourly. 500 records arrive at one partition from 2:00pm to 3:00pm. At 3:00pm, an additional 5 records arrive at the partition. You will see 500 records in storage at 3:00pm.

Refer to Confluent Cloud connector limitations for additional information.

S3 Bucket Policy

The AWS account accessing the S3 bucket must have the following permissions:

  • ListAllMyBuckets
  • ListBucket
  • GetBucketLocation
  • PutObject
  • GetObject
  • AbortMultipartUpload
  • ListMultipartUpload
  • ListMultipartUploadParts
  • ListBucketMultipartUploads

You can copy the following JSON when creating the bucket policy. Change <bucket-name> to a real bucket name. For more information, see How Do I Add an S3 Bucket Policy.

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "s3:ListAllMyBuckets"
         ],
         "Resource":"arn:aws:s3:::*"
      },
      {
         "Effect":"Allow",
         "Action":[
            "s3:ListBucket",
            "s3:GetBucketLocation"
         ],
         "Resource":"arn:aws:s3:::<bucket-name>"
      },
      {
         "Effect":"Allow",
         "Action":[
            "s3:PutObject",
            "s3:GetObject",
            "s3:AbortMultipartUpload",
            "s3:ListMultipartUploadParts",
            "s3:ListBucketMultipartUploads"

         ],
         "Resource":"arn:aws:s3:::<bucket-name>/*"
      }
   ]
}

Quick Start

Use this quick start to get up and running with the Confluent Cloud S3 sink connector. The quick start provides the basics of selecting the connector and configuring it to stream events to an S3 bucket.

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, go to Kafka API keys in your cluster or you can autogenerate the API key and secret directly in the UI when setting up the connector.
    • Create a Confluent Cloud service account for the connector.
  • (Optional) Confluent Cloud Schema Registry enabled for your cluster, if you are using a messaging schema (like Apache Avro). See Managing Schemas for Topics in Confluent Cloud.

See also

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

Using the Confluent Cloud GUI

Step 1: Launch your Confluent Cloud cluster.

See the Confluent Cloud Quick Start for installation instructions.

Step 2: Add a connector.

Click Connectors. If you already have connectors in your cluster, click Add connector.

Step 3: Select your connector.

Click the Amazon S3 Sink connector icon.

Amazon S3 Sink Connector Icon

Step 4: Enter the connector details.

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. Enter your Kafka Cluster credentials. The credentials are either the API key and secret or the service account API key and secret.

Step 5: Enter the destination details.

Complete the following and click Continue.

Important

Your AWS credentials and bucket name are validated here. Make sure you enter these correctly.

  1. Enter your AWS credentials. For information about how to set these up, see Access Keys.

  2. Enter the S3 bucket name.

  3. Select the input and output message format. Note that you must have Confluent Cloud Schema Registry configured if using a schema-based message format (like Avro).

  4. Select the Time interval that sets how you want your messages grouped in the S3 bucket. For example, if you select Hourly, messages are grouped into folders for each hour data is streamed to the bucket.

    Tip

    Time interval, Topic directory, and Path format can be used to build a directory structure for data stored in S3. For example: You set Time interval to Hourly, Topics directory to json_logs/hourly, and Path format to 'dt'=YYYY-MM-dd/'hr'=HH. The result in S3 is the directory structure: s3://<s3-bucket-name>/json_logs/daily/<Topic-Name>/dt=2020-02-06/hr=09/<files>.

  5. Enter the Flush size. This value defaults to 1000. The default value can be increased if needed.

    The following scenarios describe a couple of ways records may be flushed to storage:

    • You use the default setting of 1000 and your topic has six partitions. Files start to be created in storage after more than 1000 records exist in each partition.
    • You use the default setting of 1000 and the partitioner is set to Hourly. 500 records arrive at one partition from 2:00pm to 3:00pm. At 3:00pm, an additional 5 records arrive at the partition. You will see 500 records in storage at 3:00pm.

  6. The following are optional properties that can be used to organize your data in S3:

    • Enter a Topic directory. This is a top-level directory path to use for data stored in S3. Defaults to topics if not used.
    • Enter a Path format. This configures the time-based partitioning path created in S3. The property converts the UNIX timestamp to a date format string. If not used, this property defaults to 'year'=YYYY/'month'=MM/'day'=dd/'hour'=HH if an Hourly Time interval was selected or 'year'=YYYY/'month'=MM/'day'=dd if a Daily Time interval was selected.
    • Enter a Timestamp field name. The record field used for the timestamp, which is then used with the time-base partitioner. If not used, this defaults to the timestamp when the Kafka record was produced or stored by the Kafka broker.
    • Enter a Timezone. Use a valid timezone. For example, you can use EST, PST, WET, or UTC. Defaults to UTC if not used.
    • Enter a Locale. The locale to use with the time-based partitioner. Used to format dates and times. For example, you can use en-US for English (USA), en-GB for English (UK), en-IN for English (India), or fr-FR for French (France). Defaults to en. For a list of locale IDs, see Java locales.

  7. Enter the maximum number of tasks for the connector to use.

Configuration properties that are not shown in the Confluent Cloud UI use the default values. See Amazon S3 Sink Configuration Properties for default values and property definitions.

Step 6: Launch the connector.

Verify the following and click Launch.

  1. Make sure your data is going to the correct bucket.

  2. Check that the last directory in the path shown is using the Time Interval you entered earlier.

    Launch the connector

Step 7: Check the connector status.

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

Check the status

Step 8: Check the S3 bucket.

  1. Go to the AWS Management Console and select Storage > S3.

  2. Open your S3 bucket.

  3. Open your topic folder and each subsequent folder until you see your messages displayed.

    ../../_images/ccloud-aws-s3-details.png

Tip

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

For additional information about the S3 connector see Amazon S3 Sink Connector for Confluent Platform. Note that not all Confluent Platform S3 connector features are provided in the Confluent Cloud S3 connector.

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 S3_SINK

Example output:

Following are the required configs:
connector.class: S3_SINK
name
kafka.api.key
kafka.api.secret
aws.access.key.id
aws.secret.access.key
data.format
s3.bucket.name
time.interval
tasks.max
topics

Step 3: Create the connector configuration file.

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

{
    "name" : "confluent-s3-sink",
    "connector.class": "S3_SINK",
    "kafka.api.key": "<my-kafka-api-key>",
    "kafka.api.secret" : "<my-kafka-api-secret>",
    "aws.access.key.id" : "<my-aws-access-key>",
    "aws.secret.access.key": "<my-aws-access-key-secret>",
    "data.format": "AVRO",
    "s3.bucket.name": "s3-connector-dev",
    "time.interval" : "HOURLY",
    "flush.size": "1000",
    "tasks.max" : "1"
    "topics": "pageviews, users",
 }

Note the following required 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.

  • "data.format": Sets the input and output message format. Valid entries are AVRO, JSON, or BYTES. You must have Confluent Cloud Schema Registry configured if using a schema-based message format (like Avro).

  • "time.interval": Sets how your messages grouped in the S3 bucket. Valid entries are DAILY or HOURLY.

  • (Optional) flush.size defaults to 1000. The default value can be increased if needed.

    The following scenarios describe a couple of ways records may be flushed to storage:

    • You use the default setting of 1000 and your topic has six partitions. Files start to be created in storage after more than 1000 records exist in each partition.
    • You use the default setting of 1000 and the partitioner is set to Hourly. 500 records arrive at one partition from 2:00pm to 3:00pm. At 3:00pm, an additional 5 records arrive at the partition. You will see 500 records in storage at 3:00pm.

  • "tasks.max": Enter the maximum number of tasks for the connector to use.

  • "topics": Enter the topic name or a comma-separated list of topic names.


    Tip

    The time.interval property above and the following optional properties topics.dir and path.format can be used to build a directory structure for data stored in S3. For example: You set "time.interval" : "HOURLY", "topics.dir" : "json_logs/hourly", and "path.format" : "'dt'=YYYY-MM-dd/'hr'=HH". The result in S3 is the directory structure: s3://<s3-bucket-name>/json_logs/daily/<Topic-Name>/dt=2020-02-06/hr=09/<files>.

The following are optional properties that can be used to organize your data in S3:

  • "topics.dir": A top-level directory path to use for data stored in S3. Defaults to topics if not used.
  • ""path.format": Configures the time-based partitioning path created in S3. The property converts the UNIX timestamp to a date format string. If not used, this property defaults to 'year'=YYYY/'month'=MM/'day'=dd/'hour'=HH if an Hourly time.interval was selected or 'year'=YYYY/'month'=MM/'day'=dd if a Daily Time interval was selected.
  • timestamp.field: The record field used for the timestamp, which is used with the time-base partitioner. If not used, this defaults to the timestamp when the Kafka record was produced or stored by the Kafka broker.
  • "timezone": A valid timezone. For example, you can use EST, PST, WET, or UTC. Defaults to UTC if not used.
  • "locale". The locale to use with the time-based partitioner. Used to format dates and times. For example, you can use en-US for English (USA), en-GB for English (UK), en-IN for English (India), or fr-FR for French (France). Defaults to en. For a list of locale IDs, see Java locales.

Configuration properties that are not listed use the default values. See Amazon S3 Sink Configuration Properties for default values and property definitions.

Step 3: Load the properties 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 s3-sink-config.json

Example output:

Created connector confluent-s3-sink lcc-ix4dl

Step 4: Check the connector status.

Enter the following command to check the connector status:

ccloud connector list

Example output:

ID          |       Name        | Status  | Type
+-----------+-------------------+---------+------+
lcc-ix4dl   | confluent-s3-sink | RUNNING | sink

Step 4: Check the S3 bucket.

  1. Go to the AWS Management Console and select Storage > S3.

  2. Open your S3 bucket.

  3. Open your topic folder and each subsequent folder until you see your messages displayed.

    ../../_images/ccloud-aws-s3-details.png

Tip

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

For additional information about the S3 connector see Amazon S3 Sink Connector for Confluent Platform. Note that not all Confluent Platform S3 connector features are provided in the Confluent Cloud S3 connector.

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. The demo also shows how to use Confluent Cloud CLI to manage your resources in Confluent Cloud.