Amazon SQS Source Connector for Confluent Cloud¶
Note
If you are installing the connector locally for Confluent Platform, see Amazon SQS Source Connector for Confluent Platform.
The Kafka Connect Amazon Simple Queue Service (SQS) Source connector is used to move messages from an Amazon SQS Queue into Apache Kafka®. It supports both Standard queues and First-In-First-Out (FIFO) queues. The connector polls an Amazon SQS queue, converts SQS messages into Kafka records, and then pushes the records into a Kafka topic.
The connector converts an Amazon SQS message into a Kafka record, with the following structure:
- The key encodes the SQS queue name and message ID in a struct. For FIFO queues, it also includes the message group ID.
- The value encodes the body of the SQS message and various message attributes in a struct.
- Each header encodes message attributes that may be present in the SQS message.
For record schema details, see Record Schemas.
For standard queues, the connector supports best-effort ordering guarantees. This means that there is a chance records will end up in a different order in Kafka.
For FIFO queues, the connector guarantees records are inserted into Kafka in the order they were inserted in Amazon SQS, as long as the destination Kafka topic has exactly one partition. If the destination topic has more than one partition, you can use a Single Message Transforms (SMT) to set the partition based on the MessageGroupId field in the key.
Note that the connector provides least once delivery. This means there is a chance that the connector can introduce duplicate records in Kafka for both standard and FIFO queues.
Features¶
The Amazon SQS Source connector provides the following features:
- Topics created automatically: The connector can automatically create Kafka topics.
- At least once delivery: The connector guarantees that records are delivered at least once to the Kafka topic.
- Supports multiple tasks: The connector supports running one or more tasks. More tasks may improve performance.
- Automatic retries: The connector will retry all requests (that can be retried) when the Amazon SQS service is unavailable. This value defaults to three retries.
- Supported data formats: The connector supports Avro, JSON Schema (JSON-SR), Protobuf, and JSON (schemaless) output formats. Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON Schema, or Protobuf). See Environment Limitations for additional information.
For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.
Limitations¶
Be sure to review the following information.
- For connector limitations, see Amazon SQS Source 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 Environment Limitations.
Quick Start¶
Use this quick start to get up and running with the Confluent Cloud Amazon SQS Source connector. The quick start provides the basics of selecting the connector and configuring it to stream events.
- Prerequisites
- Authorized access to a Confluent Cloud cluster on Amazon Web Services (AWS), Microsoft Azure (Azure), or Google Cloud Platform (GCP).
- The Confluent CLI installed and configured for the cluster. See Install the Confluent CLI.
- For networking considerations, see Networking and DNS Considerations. To use static egress IPs, see Static Egress IP Addresses.
- An AWS account configured with Access Keys. You use these access keys when setting up the connector.
- Amazon SQS connection details. For more information, see Setting up Amazon SQS.
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 4: Set up the connection.¶
Note
- Make sure you have all your prerequisites completed.
- An asterisk ( * ) designates a required entry.
- Enter a connector Name.
- Select the way you want to provide Kafka Cluster credentials. You can either select a service account resource ID or you can enter an API key and secret (or generate these in the Cloud Console).
- Enter the Kafka topic name where you want data sent. The connector can create a topic automatically if no topics exist.
- Enter your AWS credentials. For information about how to set these up, see Access Keys.
- Enter the Amazon SQS connection details:
- Fully qualified SQS URL: For example,
https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue
. For details, see Amazon SQS queue and message identifiers. - SQS Region: The AWS region that the SQS queue belongs to. If left empty, the connector attempts to infer the region from the SQS URL.
- Fully qualified SQS URL: For example,
- Select the Output Kafka record value format (data going to the Kafka topic): AVRO, JSON_SR (JSON Schema), PROTOBUF, or JSON (schemaless). Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf). See Environment Limitations for additional information.
- Enter the number of tasks to use with the connector. More tasks may improve performance.
- Transforms and Predicates: See the Single Message Transforms (SMT) documentation for details.
See Configuration Properties for all 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 for records.¶
Verify that records are being produced at the Kafka topic.
For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.
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.
- The example commands use Confluent CLI version 2. For more information see, Confluent CLI v2.
Step 1: List the available connectors.¶
Enter the following command to list available connectors:
confluent connect plugin list
Step 2: Show the required connector configuration properties.¶
Enter the following command to show the required connector properties:
confluent connect plugin describe <connector-catalog-name>
For example:
confluent connect plugin describe SqsSource
Example output:
Following are the required configs:
connector.class: SqsSource
name
kafka.auth.mode
kafka.api.key
kafka.api.secret
sqs.url
kafka.topic
aws.access.key.id
aws.secret.key.id
output.data.format
tasks.max
Step 3: Create the connector configuration file.¶
Create a JSON file that contains the connector configuration properties. The following entry shows the required configuration properties.
{
"name": "SqsSource_0",
"config": {
"connector.class": "SqsSource",
"name": "SqsSource_0",
"kafka.auth.mode": "KAFKA_API_KEY",
"kafka.api.key": "<my-kafka-api-key>",
"kafka.api.secret": "<my-kafka-api-secret>",
"sqs.url": "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue",
"kafka.topic": "stocks",
"aws.access.key.id": "<INSERT AWS API KEY>",
"aws.secret.access.key": "<INSERT AWS API SECRET>",
"output.data.format": "JSON",
"tasks.max": "1"
}
}
Note the following property definitions:
"connector.class"
: Identifies the connector plugin name."name"
: Sets a name for your new connector.
"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
"sqs.url"
: For example,https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue
. For details, see Amazon SQS queue and message identifiers."sqs.region"
: The AWS region that the SQS queue belongs to. If this property is not used, the connector attempts to infer the region from the SQS URL."aws.access.key.id"
and"aws.secret.access.key"
: Enter the AWS Access Key ID and Secret. For information about how to set these up, see Access Keys."output.data.format"
: Enter an output data format (data going to the Kafka topic): AVRO, JSON_SR (JSON Schema), PROTOBUF, or JSON (schemaless). Schema Registry must be enabled to use a Schema Registry-based format (for example, Avro, JSON_SR (JSON Schema), or Protobuf). See Environment Limitations for additional information."tasks.max"
: Enter the number of tasks to use with the connector. More tasks may improve performance.
Single Message Transforms: See the Single Message Transforms (SMT) documentation for details about adding SMTs using the CLI.
See Configuration Properties for all property values and descriptions.
Step 4: Load the properties file and create the connector.¶
Enter the following command to load the configuration and start the connector:
confluent connect create --config <file-name>.json
For example:
confluent connect create --config sqs-source-config.json
Example output:
Created connector SqsSource_0 lcc-do6vzd
Step 5: Check the connector status.¶
Enter the following command to check the connector status:
confluent connect list
Example output:
ID | Name | Status | Type | Trace
+------------+------------------+---------+--------+-------+
lcc-do6vzd | SqsSource_0 | RUNNING | source | |
Step 6: Check for records.¶
Verify that records are being produced at the Kafka topic.
For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect section.
Configuration Properties¶
Use the following configuration properties with this connector.
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
- 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
- Type: password
- Importance: high
Which topic do you want to send data to?¶
kafka.topic
Identifies the topic name to write the data to.
- Type: string
- Importance: high
AWS Credentials¶
aws.access.key.id
The Amazon Access Key used to connect to SQS.
- Type: password
- Importance: high
aws.secret.key.id
The Amazon Secret Key used to connect to SQS.
- Type: password
- Importance: high
How should we connect to Amazon SQS?¶
sqs.url
Fully qualified Amazon SQS URL to read messages from
- Type: string
- Importance: high
sqs.region
The AWS region that the SQS queue belongs to. If left empty, the connector will attempt to infer the region from the SQS URL.
- Type: string
- Importance: medium
Output messages¶
output.data.format
Sets the output 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
- Importance: high
Number of tasks for this connector¶
tasks.max
- Type: int
- Valid Values: [1,…]
- Importance: high
Record Schemas¶
The Amazon SQS Source connector creates records using following schemas.
Key Schema¶
The Key is a struct
with the following fields:
Field Name | Schema Type | Optional? | Description |
---|---|---|---|
QueueUrl | string | mandatory | The fully qualified SQS queue URL from which the record is generated. |
MessageId | string | mandatory | The unique message ID of the message within Amazon SQS. |
MessageGroupId | string | optional | For FIFO queues, this is the message group ID. |
Value Schema¶
The Value is a struct
with the following fields:
Field Name | Schema Type | Optional? | Description |
---|---|---|---|
Body | string | The body of the SQS message. | |
ApproximateFirstReceiveTimestamp | int64 | Returns the time the message was first received from the queue (epoch time in milliseconds). | |
ApproximateReceiveCount | int32 | Returns the number of times a message has been received across all queues but not deleted. | |
SenderId | string | The IAM user or role that sent this message to SQS. | |
SentTimestamp | int64 | Returns the time the message was sent to the queue (epoch time in milliseconds | |
MessageDeduplicationId | string | Optional | Returns the value provided by the producer that calls the SendMessage action. |
MessageGroupId | string | Optional | Returns the value provided by the producer that calls the SendMessage action. Messages with the same MessageGroupId are returned in sequence. |
SequenceNumber | string | Returns the value provided by Amazon SQS. |
For more information, see Request Parameters.
Header Schema¶
Each message attribute in SQS is converted to a Header in Kafka.
- The header key is the name of the message attribute.
- The header value is the value of the message attribute.
- The header schema depends on the data type of the message attribute.
- String message attributes use a string schema.
- Number message attributes use a string schema.
- Binary message attributes use a bytes schema.
- Custom message attributes use either string or bytes, depending on the type of custom attribute.
For more information, see Message attribute components.
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 CLI to manage your resources in Confluent Cloud.