<a id="generalized-s3source-connector"></a>

# Generalized Amazon S3 Source Connector for Confluent Platform

The Generalized Kafka Connect Amazon S3 Source connector can read data from any
type of file naming convention listed under an S3 bucket, and the filenames
don’t have to be in a specific format. As long as the files are in any of the
supported formats (for example, JSON, Avro and Byte Array) the connector will be
able to read them.

#### IMPORTANT
<!-- WARNING: THIS IS A SHARED FILE AND THE SOURCE IS LOCATED IN DOCS-COMMON. DO NOT ADD TO ANY OTHER REPO. -->

Effective July 6, 2025, only self-managed connector versions that meet or exceed the minimum version listed on the
[Supported Connector Versions](https://docs.confluent.io/platform/7.8/connect/supported-connector-version.html#supported-connector-versions-till-cp-7-8)
page receive support from Confluent. Older, unsupported connector versions have been removed from Confluent Marketplace and
are no longer available for download.

<a id="generalized-s3source-features"></a>

## Features

The Generalized Amazon S3 Source connector includes the following features:

- [At least once delivery](#generalized-s3source-at-least-once-delivery)
- [Multiple tasks](#generalized-s3source-multiple-tasks)
- [Client-side encryption](#generalized-s3source-csfle-sm)

<a id="generalized-s3source-at-least-once-delivery"></a>

### At least once delivery

In the event of a task failure the connector guarantees no messages are lost,
although the last few messages may be processed again.

<a id="generalized-s3source-multiple-tasks"></a>

### Multiple tasks

The Generalized Amazon S3 Source connector supports running one or more tasks.
You can specify the number of tasks in the `tasks.max` configuration
parameter. This can lead to huge performance gains when multiple files need to
be parsed.

<a id="generalized-s3source-csfle-sm"></a>

### Client-side encryption

This connector supports Client-Side Field Level Encryption (CSFLE) and Client-Side Payload Encryption (CSPE). For more information, see [Manage Client-Side Encryption](https://docs.confluent.io/platform/current/connect/manage-csfle.html).

## Limitations

The Generalized S3 Source connector has the following limitations:

- The connector is incompatible with the Connect eager rebalancing protocol.
- The connector won’t reload data during the following scenarios:
  - Renaming a file which the connector has already read.
  - Uploading a newer version of a file with a new record.

You should also be aware of the following connector actions:

- The connector ignores any S3 object with a name that does not start with the
  configured `topics.dir` directory. This name is `topics/` by default.
- The connector uses the connector name to store offsets on how much of the
  bucket it has processed. Deleting a connector and using the same name will not
  cause the connector to reprocess from the beginning but will save the
  progress of the original connector unless the corresponding entry in the
  offset topic is cleared.
- For a new bucket, you need to create a new connector with an unused name. If
  you reconfigure an existing connector to source from the new bucket, or
  create a connector with a name that is used for another connector, the
  connector will not source from the beginning of data stored in the bucket.
  This is because the connector will maintain offsets tied to the connector
  name.

<a id="generalized-s3source-connector-install"></a>

## Install the Amazon S3 Source Connector

#### IMPORTANT
- If you’re upgrading from a previous version of the S3 Source connector, be
  sure to configure the connector to skip files in your buckets that have
  already been processed, as the partition offsets used by the Restore and
  Backup S3 Source connector will no longer be used by the Generalized S3
  Source connector.
- Version 2.0.0 and later of Storage Source connectors do not
  support CP versions earlier than version 6.0.0.

You can install this connector by using the [confluent connect
plugin
install](https://docs.confluent.io/confluent-cli/current/command-reference/connect/plugin/confluent_connect_plugin_install.html)
command, or by manually downloading the ZIP file.

### Prerequisites

For full functionality, the Generalized S3 Source connector requires the
following AWS permissions:

- ListBucket
- GetObject

- You must install the connector on every machine where Connect will run.
- An installation of the latest (`latest`) connector version.

  To install the `latest` connector version, navigate to your Confluent Platform
  installation directory and run the following command:
  ```bash
  confluent connect plugin install confluentinc/kafka-connect-s3-source:latest
  ```

  You can install a specific version by replacing `latest` with a version
  number as shown in the following example:
  ```bash
  confluent connect plugin install confluentinc/kafka-connect-s3-source:1.0.0-preview
  ```

### Install the connector manually

[Download and extract the ZIP file](https://www.confluent.io/hub/confluentinc/kafka-connect-s3-source) for your
connector and then follow the manual connector installation
[instructions](/kafka-connectors/self-managed/userguide.html#connect-installing-plugins).

<a id="generalized-s3source-connector-license"></a>

## License

You can use this connector for a 30-day trial period without a license key.

After 30 days, you must purchase a connector subscription which includes [Confluent enterprise license](/platform/current/installation/license.html#enterprise-subscription-license) keys to subscribers, along with [enterprise-level support](https://www.confluent.io/subscription/) for Confluent Platform and your connectors. If you are a subscriber, you can contact [Confluent Support](https://support.confluent.io/) for more information.

See [Confluent license properties](https://docs.confluent.io/kafka-connect-s3-source/current/configuration_options.html#confluent-license-properties) for license properties and information about the license topic.

## Configuration Properties

For a complete list of configuration properties for this connector, see
[Configuration Reference for Amazon S3 Source Connector for Confluent Platform](../configuration_options.md#s3-source-configuration-options).

For an example of how to get Kafka Connect connected to [Confluent Cloud](/cloud/current/index.html), see
[Connect Self-Managed Kafka Connect to Confluent Cloud](/cloud/current/cp-component/connect-cloud-config.html#distributed-cluster).

<a id="generalized-s3source-migration"></a>

## Upgrading to Version 3.x

Starting with version 3.x, the Generalized Amazon S3 Source connector uses the AWS SDK v2, upgrading from v1.
This upgrade does not allow backward compatibility with versions 1.x and 2.x. If you use any custom or
built-in AWS credentials providers, you must update your implementation to ensure compatibility
with the new AWS SDK v2.

Follow the steps below based on the type of credentials provider your implementation uses.

### Custom credentials provider

- Update [credentials provider](#generalized-s3source-credentials-providers) interface: If you have implemented a
  custom credentials provider, you must update your code to implement the new AWS SDK v2 interface.

  Old interface: [com.amazon.auth.AWSCredentialsProvider](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html?session_ref=direct)

  New interface: [software.amazon.awssdk.auth.credentials.AwsCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/AwsCredentialsProvider.html)
- Set a new instantiation method: The connector no longer uses a default no-args constructor to create
  an instance of your custom provider. Instead, your credentials provider class must now implement
  a static, no-argument `create()` method that returns a new instance of your provider.

### AWS built-in credentials provider

- Use v2 equivalent: If you use a credentials provider built into the AWS SDK itself, you must ensure you use the v2
  equivalent of that provider.
- Use `create()` method: This provider must implement a static, no-argument `create()`
  method that returns a new provider instance.

### Default credentials provider

- Review changes to the [default chain](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/credentials-chain.html):
  The default credentials provider chain in the AWS SDK v2 has changed the order in which
  it searches for credentials. The SDK v2 version now checks for system properties before checking
  for environment variables. This change may affect your connector’s authentication if you
  previously relied on environment variables and also have system properties set.

For more information about credentials provider migration, see
[Credentials provider changes for AWS SDK v2](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/migration-client-credentials.html).

<a id="generalized-s3source-object-formats"></a>

## S3 Object Formats

The Generalized S3 Source connector can read different file formats in S3 and
serialize them into Kafka records. This is controlled by the connector’s
`format.class` configuration property, which has several options:

- **Avro**: Use `format.class=io.confluent.connect.s3.format.avro.AvroFormat`
  to source Avro container files.
- **JSON**: Use `format.class=io.confluent.connect.s3.format.json.JsonFormat`
  to source JSON files. Supported JSON formats are line-delimited JSON, record
  separator-limited JSON, and concatenated JSON.
- **Raw Bytes**: Use
  `format.class=io.confluent.connect.s3.format.bytearray.ByteArrayFormat` to
  parse the S3 object content as raw bytes. The default line separator will be the
  newline character, but this can be customized with the
  `format.bytearray.separator` configuration property.
- **Strings**: Use
  `format.class=io.confluent.connect.s3.format.string.StringFormat` to parse the S3 object content as Strings.

<a id="generalized-s3source-credentials-providers"></a>

## AWS Credentials

The following sections provide information about how to configure an S3
connector to provide credentials when connecting to AWS.

### Credentials provider chain

By default, the S3 connector looks for S3 credentials in the following locations and in the following order:

1. The `aws.accessKeyId` and `aws.secretAccessKey` Java system properties on the Connect worker processes where the connector will be deployed. However, these variables are only recognized by the AWS SDK for Java and are not recommended.
2. The `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables accessible to the Connect worker processes where the connector will be deployed. These variables are recognized by the AWS CLI and all AWS SDKs (except for the AWS SDK for .NET). You use export to set these variables.
   ```bash
   export AWS_ACCESS_KEY_ID=<your_access_key_id>
   export AWS_SECRET_ACCESS_KEY=<your_secret_access_key>
   ```
3. A call will be made to the AWS Security Token Service (AWS STS) using the configured environment variables or system properties to fetch the credentials. The credentials provider looks for the following environment variables or JVM system properties:
   `AWS_WEB_IDENTITY_TOKEN_FILE` or `aws.webIdentityTokenFile`, `AWS_ROLE_ARN` or `aws.roleArn` and `AWS_ROLE_SESSION_NAME` or `aws.roleSessionName` (optional).
4. The `~/.aws/credentials` file located in the home directory of the operating system user that runs the Connect worker processes. These credentials are recognized by most AWS SDKs and the AWS CLI. Use the following AWS CLI command to create the credentials file:
   ```bash
   aws configure
   ```

   You can also manually create the credentials file using a text editor. The file should contain lines in the format shown in the example below. See [AWS Credentials File Format](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-file-format) for additional details.
   ```bash
   [default]
   aws_access_key_id = <your_access_key_id>
   aws_secret_access_key = <your_secret_access_key>
   ```

   #### NOTE
   When creating the credentials file, make sure that the user creating the credentials file is the same user that runs the Connect worker processes and that the credentials file is in this user’s home directory. Otherwise, the S3 connector will not be able to find the credentials.
5. A query sent to `http://169.254.170.2${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}` to return AWS credentials. This is applicable only if the Connect worker processes are running in AWS containers.
6. A metadata query that returns credentials from an EC2 instance. This is applicable only if the Connect worker processes are running in EC2 instances.

Choose one of the above to define the AWS credentials that the S3 connectors use, verify the credentials implementation is set correctly, and then restart all of the Connect worker processes.

#### NOTE
Confluent recommends using either **Environment variables** or a **Credentials file** because these are the most straightforward, and they can be checked using the AWS CLI tool before running the connector.

All S3 connectors run in a single Connect worker cluster and use the same credentials. This is sufficient for many use cases. If you want more control, refer to the following section to learn more about controlling and customizing how the S3 connector gets AWS credentials.

### Credentials providers

A credentials provider is a Java class that implements the
[software.amazon.awssdk.auth.credentials.AwsCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/AwsCredentialsProvider.html)
interface in the AWS Java library and returns AWS credentials from the
environment. By default the S3 connector configuration property
`s3.credentials.provider.class` uses the
[software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html)
class. This class and interface implementation chains together six other
credential provider classes. The [DefaultCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/DefaultCredentialsProvider.html)
implementation looks for credentials in the following order:

1. **Java system properties** using the [SystemPropertyCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/SystemPropertyCredentialsProvider.html) class implementation. This implementation uses Java system properties `aws.accessKeyId` and `aws.secretAccessKey`.
2. **Environment variables** using the [EnvironmentVariableCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/EnvironmentVariableCredentialsProvider.html) class implementation. This implementation uses environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
3. **WebIdentityTokenFileCredentialsProvider** using the [WebIdentityTokenFileCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/WebIdentityTokenFileCredentialsProvider.html) class implementation. This implementation uses a token file, role ARN, and role session name to return AWS credentials. The environment variables `AWS_WEB_IDENTITY_TOKEN_FILE`, `AWS_ROLE_ARN`, and `AWS_ROLE_SESSION_NAME` must be set for this provider to work. For additional information about setting up this provider, see [Using Web Identity Federation to Assume Roles for Service Accounts](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc.html).
4. **Credentials file** using the [ProfileCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/ProfileCredentialsProvider.html) class implementation. This implementation uses a credentials file located in the path `~/.aws/credentials`. This credentials provider can be used by most AWS SDKs and the AWS CLI. Use the following AWS CLI command to create the credentials file:
   ```bash
   aws configure
   ```

   You can also manually create the credentials file using a text editor. The file should contain lines in the format shown in the example below. See [AWS Credentials File Format](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html#credentials-file-format) for additional details.
   ```bash
   [default]
   aws_access_key_id = <your_access_key_id>
   aws_secret_access_key = <your_secret_access_key>
   ```

   #### NOTE
   When creating the credentials file, make sure that the user creating the credentials file is the same user that runs the Connect worker processes and that the credentials file is in this user’s home directory. Otherwise, the S3 connector will not be able to find the credentials.
5. **Amazon Elastic Container Service (ECS) container credentials** using the [ContainerCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/ContainerCredentialsProvider.html) class implementation. This implementation uses a query sent to `http://169.254.170.2${AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}` to return AWS credentials for the S3 connector. For this provider to work, the environment variable `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` or `AWS_CONTAINER_CREDENTIALS_FULL_URI` must be set. For additional information about setting up this query, see [IAM Roles for Tasks](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html).
6. **EC2 instance profile credentials** using the [InstanceProfileCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/InstanceProfileCredentialsProvider.html) class implementation. EC2 instance metadata is queried for credentials. See [Amazon EC2 metadata service](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html) for additional information about instance metadata queries. For additional information and updates from AWS, see [Working with AWS credentials](https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html).

   #### NOTE
   EC2 instance profile credentials can be used only if the environment variable `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI` is not set. For more information, see [EC2ContainerCredentialsProviderWrapper](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/index.html?com/amazonaws/auth/EC2ContainerCredentialsProviderWrapper.html).

### Using trusted account credentials

This connector can assume a role and use credentials from a separate trusted
account. This is a default feature provided with recent versions of this
connector that include an updated version of the AWS SDK.

#### IMPORTANT
You cannot use assumed role credentials to access AWS through a proxy server without first passing [environment variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-proxy.html) or [system properties](https://confluence.atlassian.com/kb/how-to-configure-outbound-http-and-https-proxy-for-your-atlassian-application-834000120.html). This is due to an AWS SDK [limitation](https://github.com/aws/aws-sdk-java/issues/2558).

After you create the trust relationship, an IAM user or an application from the trusted account can
use the [AWS Security Token Service (AWS STS)](https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html)
`AssumeRole` API operation. This operation provides temporary security credentials that enable
access to AWS resources for the connector. For details, see
[Creating a Role to Delegate Permissions to an IAM User](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html).

Example:
: ```bash
  Profile in ~/.aws/credentials:
  <br/>
  [default]
  role_arn=arn:aws:iam::037803949979:role/kinesis_cross_account_role
  source_profile=staging
  role_session_name = OPTIONAL_SESSION_NAME
  <br/>
  [staging]
  aws_access_key_id = <STAGING KEY>
  aws_secret_access_key = <STAGING SECRET>
  ```

To allow the connector to assume a role with the right permissions, set the
[Amazon Resource Name (ARN)](https://docs.aws.amazon.com/credref/latest/refdocs/setting-global-role_arn.html)
for this role. Additionally, you must choose between `source_profile` or `credential_source`
as the way to get credentials that have permission to assume the role, in the environment where the
connector is running.

#### NOTE
When setting up trusted account credentials, be aware that the approach of loading profiles from
both `~/.aws/credentials` and `~/.aws/config` does not work when configuring this connector.
Assumed role settings and credentials must be placed in the `~/.aws/credentials` file.

Additionally, the connector implements the `AwsAssumeRoleCredentialsProvider` which means
you can use the following configs to configure the assume role operation.

```bash
s3.credentials.provider.class=io.confluent.connect.s3.auth.AwsAssumeRoleCredentialsProvider
s3.credentials.provider.sts.role.arn=arn:aws:iam::012345678901:role/my-restricted-role
s3.credentials.provider.sts.role.session.name=session-name
s3.credentials.provider.sts.role.external.id=external-id
```

### Using Other Implementations

You can use a different credentials provider. To do this, set the `s3.credentials.provider.class` property to the name of any class that implements the [software.amazon.awssdk.auth.credentials.AwsCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/AwsCredentialsProvider.html) interface.

Complete the following steps to use a different credentials provider:

1. Find or create a Java credentials provider class that implements the [software.amazon.awssdk.auth.credentials.AwsCredentialsProvider](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/auth/credentials/AwsCredentialsProvider.html) interface.
2. Put the class file in a JAR file.
3. Place the JAR file in the `share/java/kafka-connect-s3` directory on **all Connect workers**.
4. Restart the Connect workers.
5. Change the S3 connector property file to use your custom credentials. Add the provider class entry `s3.credentials.provider.class=<className>` in the S3 connector properties file.

   #### IMPORTANT
   You must use the fully qualified class name in the `<className>` entry.

<a id="generalized-s3source-connector-quickstart"></a>

## Quick Start

In the following example, the Generalized S3 Source connector reads all data
listed under a specific S3 bucket and then loads them into a Kafka topic. You may
use any file naming convention writing when data to the S3 bucket.

1. Upload the following data under a folder name `quickstart` within the
   targeted S3 bucket. In this example JSON format is used, which supports the
   following: line-delimited JSON, concatenated
   JSON, and a JSON array of records.
   ```json
   {"f1": "value1"}
   {"f1": "value2"}
   {"f1": "value3"}
   {"f1": "value4"}
   {"f1": "value5"}
   {"f1": "value6"}
   {"f1": "value7"}
   {"f1": "value8"}
   {"f1": "value9"}
   ```
2. Install the connector by running the following command from your Confluent Platform
   installation directory:
   ```bash
   confluent connect plugin install confluentinc/kafka-connect-s3-source:latest
   ```
3. Create a `quickstart-s3source-generalized.properties` file with the
   following contents:
   ```properties
   name=quick-start-s3-source
   connector.class=io.confluent.connect.s3.source.S3SourceConnector
   tasks.max=1
   value.converter=org.apache.kafka.connect.json.JsonConverter
   mode=GENERIC
   topics.dir=quickstart
   format.class=io.confluent.connect.s3.format.json.JsonFormat
   topic.regex.list=quick-start-topic:.*
   s3.bucket.name=healthcorporation
   value.converter.schemas.enable=false
   ```

   #### NOTE
   For more information about accepted regular expressions,
   see [Google RE2 syntax](https://github.com/google/re2/wiki/Syntax/).
4. Load the Generalized S3 Source connector.
   ```bash
   confluent local services connect connector load quick-start-s3-source --config quickstart-s3source-generalized.properties
   ```
5. Confirm the connector is in a `RUNNING` state:
   ```bash
   confluent local services connect connector status quick-start-s3-source
   ```
6. Confirm that the messages are being sent to Kafka.
   ```bash
   kafka-console-consumer \
       --bootstrap-server localhost:9092 \
       --topic quick-start-topic \
       --from-beginning
   ```
7. The response should be 9 records as shown in the following example:
   ```bash
   {"f1": "value1"}
   {"f1": "value2"}
   {"f1": "value3"}
   {"f1": "value4"}
   {"f1": "value5"}
   {"f1": "value6"}
   {"f1": "value7"}
   {"f1": "value8"}
   {"f1": "value9"}
   ```

## Troubleshooting Connector and Task Failures

### Stack Trace

You can use the Connect [Kafka Connect REST
Interface](/platform/current/connect/references/restapi.html) to check the status of the connectors
and tasks. If a task or connector has failed, the `trace` field will include a
reason and a stack trace.

### Stack Trace message: No new files ready after scan task…

If this message is displayed, complete the following steps:

1. Review your `topics.dir` configuration property to ensure you have
   configured the right folder under the S3 bucket. If you do not set this
   parameter, the connector expects the data to be under the default
   folder which is `topics`.
2. Review the `topic.regex` configuration property to ensure your expression
   matches your data in the S3 bucket to the Kafka topic.
