AWS Lambda Sink Connector for Confluent Cloud

Note

If you are installing the connector locally for Confluent Platform, see AWS Lambda Sink Connector for Confluent Platform.

The AWS Lambda function can be invoked by this connector either synchronously or asynchronously.

  • In synchronous mode, records within a topic and partition are processed sequentially. Records within different topic partitions can be processed in parallel. The response from AWS Lambda is written to success-<connector-id> topic. If an error occurs during Lambda execution, the connector is configured to write the error to the error-<connector-id> topic and proceed. For additional details about Lambda invocation, see Synchronous invocation.
  • In asynchronous mode, the connector operates in a fire-and-forget mode. Records are processed on a best-effort, sequential basis. The connector does not attempt any retries. AWS Lambda automatically retries up to two times, after which AWS Lambda can move the request to a dead letter queue. For additional details about Lambda invocation, see Ansynchronous invocation.

Features

The AWS Lambda Sink connector provides the following features:

  • Synchronous and Asynchronous Lambda function invocation: The AWS Lambda function can be invoked by this connector either synchronously or asynchronously.

  • At-least-once delivery: The connector guarantees at-least-once processing semantics. Under certain circumstances, a record may be processed more than once. You should design your AWS Lambda function to be idempotent. If you have configured the connector to log the response from the Lambda function to a Kafka topic, the topic can contain duplicate records. You can enable Kafka log compaction on the topic to remove duplicate records. Alternatively, you can write a ksqlDB query to detect duplicate records in a time window.

  • Supports multiple tasks: The connector supports running one or more tasks. More tasks may improve performance.

  • Results topics: In synchronous mode, AWS Lambda results are stored in the success-<connector-id> and error-<connector-id> topics.

  • Input Data Format with or without a Schema: The connector supports input data from Kafka topics in Avro, JSON Schema (JSON_SR), Protobuf, JSON (schemaless), or Bytes format. Schema Registry must be enabled to use a Schema Registry-based format.

    Note

    If no schema is defined, values are encoded as plain strings. For example, "name": "Kimberley Human" is encoded as name=Kimberley Human.

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.

Quick Start

Use this quick start to get up and running with the Confluent Cloud AWS Lambda Sink connector. The quick start provides the basics of selecting the connector and configuring it to send records to AWS Lambda.

Prerequisites
  • Authorized access to a Confluent Cloud cluster on AWS.

  • 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 Environment Limitations for additional information.

    Note

    If no schema is defined, values are encoded as plain strings. For example, "name": "Kimberley Human" is encoded as name=Kimberley Human.

  • For networking considerations, see Networking and DNS Considerations. To use static egress IPs, see Static Egress IP Addresses.

  • Your AWS Lambda project should be in the same region as your Confluent Cloud cluster where you are running the connector.

  • An AWS account configured with Access Keys.

  • You need to configure a Lambda IAM policy for the account to allow lambda:InvokeFunction and lambda:GetFunction. The following shows a JSON example for setting this policy:

    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "lambda:InvokeFunction",
                    "lambda:GetFunction"
                ],
                "Resource": "*"
            }
        ]
    }
    
  • 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 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 AWS Lambda Sink connector icon.

AWS Lambda Sink Connector Icon

Step 4: Enter the connector details.

Note

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

At the Add AWS Lambda Sink Connector screen, complete the following:

If you’ve already populated your Kafka topics, select the topic(s) you want to connect from the Topics list.

To create a new topic, click +Add new topic.

Step 5: Check the Lambda function metrics.

Go to the AWS Lambda console, open the Lambda function, and verify that records are processing. You can check for processing on the Monitoring tab on the Lambda function page. In synchronous mode, AWS Lambda results are stored in the following topics:

  • success-<connector-id>
  • error-<connector-id>

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 CLI to manage your resources in Confluent Cloud.

../_images/topology.png

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 LambdaSink

Example output:

Following are the required configs:
connector.class: LambdaSink
name
topics
input.data.format
connector.class
kafka.auth.mode
kafka.api.key
kafka.api.secret
aws.access.key.id
aws.secret.access.key
aws.lambda.function.name
aws.lambda.invocation.type
tasks.max

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.

{
  "connector.class": "LambdaSink",
  "name": "LambdaSinkConnector_0",
  "topics": "users",
  "input.data.format": "JSON",
  "connector.class": "LambdaSink",
  "kafka.auth.mode": "KAFKA_API_KEY",
  "kafka.api.key": "****************",
  "kafka.api.secret": "*************************************************",
  "aws.access.key.id": "****************",
  "aws.secret.access.key": "********************************************",
  "aws.lambda.function.name": "myLambdaFunction",
  "aws.lambda.invocation.type": "sync",
  "behavior.on.error": "fail",
  "tasks.max": "1"
}

Note the following required property definitions:

  • "connector.class": Identifies the connector plugin name.
  • "name": Sets a name for your new connector.
  • "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 or KAFKA_API_KEY (the default). To use an API key and secret, specify the configuration properties kafka.api.key and kafka.api.secret, as shown in the example configuration (above). To use a service account, specify the Resource ID in the property kafka.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 (JSON Schema), PROTOBUF, JSON (Schemaless), or BYTES. You must have Confluent Cloud Schema Registry configured if using a schema-based message format.

    Note

    If no schema is defined, values are encoded as plain strings. For example, "name": "Kimberley Human" is encoded as name=Kimberley Human.

  • "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.

  • "aws.lambda.function.name": Enter the Lambda function to invoke. For additional information, see the What is AWS Lambda.

  • "aws.lambda.invocation.type":

    • "sync": Records within a topic and partition are processed sequentially. Records within different topic partitions can be processed in parallel. If configured, the response from AWS Lambda can be written to a Kafka topic. If an error occurs during Lambda execution, the connector can be configured to either ignore the error and proceed, log the error, or stop the connector completely. For additional details about Lambda invocation, see Synchronous invocation.
    • "async": The connector operates in a fire-and-forget mode. Records are processed on a best-effort, sequential basis. The connector does not attempt any retries. AWS Lambda automatically retries up to two times, after which AWS Lambda can move the request to a dead letter queue. For additional details about Lambda invocation, see Ansynchronous invocation.
  • "behavior.on.error": Select the error handling behavior for the AWS Lambda function invocations:

    • "fail": Stops the connector in case of an error.
    • "ignore": Continues to process next set of records.
    • "log": Logs the error message in error-<connector-id> topic and continues processing.

    Note

    The setting is only applicable when aws.lambda.invocation.type is set to sync mode.

  • "tasks.max": Enter the number of tasks in use by the connector. Refer to Confluent Cloud connector limitations for additional information.

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 definitions.

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 lambda-sink-config.json

Example output:

Created connector LambdaSinkConnector_0 lcc-ix4dl

Step 5: Check the connector status.

Enter the following command to check the connector status:

confluent connect list

Example output:

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

Step 6: Check the Lambda function metrics.

Go to the AWS Lambda console, open the Lambda function, and verify that records are processing. You can check for processing on the Monitoring tab on the Lambda function page. In synchronous mode, AWS Lambda results are stored in the following topics:

  • success-<connector-id>
  • error-<connector-id>

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.

Configuration Properties

Use the following configuration properties with this connector.

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

Input messages

input.data.format

Sets the input Kafka record value format. Valid entries are AVRO, JSON_SR, PROTOBUF, JSON or BYTES. 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

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

AWS credentials

aws.access.key.id

The Amazon Access Key used to connect to AWS Lambda.

  • Type: password
  • Importance: high
aws.secret.access.key

The Amazon Secret Key used to connect to AWS Lambda.

  • Type: password
  • Importance: high

How should we connect to AWS Lambda?

aws.lambda.function.name

The AWS Lambda function to invoke.

  • Type: string
  • Importance: high
aws.lambda.region

The AWS region where the lambda is defined. If no value for this property is provided, the value specified for the ‘kafka.region’ property is used.

  • Type: string
  • Importance: low

Lambda details

aws.lambda.invocation.type

The mode in which the AWS Lambda function is invoked. Two modes are supported; sync: In this mode, records are processed sequentially. The result or error from AWS Lambda function can optionally be saved to Kafka topics, success-<connector-id> or error-<connector-id>. async: In this mode, records may not be processed sequentially. The connector does not save the result or error from the AWS Lambda function execution. You can configure a dead letter queue in AWS to record function errors.

  • Type: string
  • Default: sync
  • Importance: high
aws.lambda.batch.size

The maximum number of Kafka records to combine in a single AWS Lambda function invocation. You should set this as high as possible, without exceeding AWS Lambda invocation payload limits. To disable batching of records, set this value to 1.

  • Type: int
  • Default: 20
  • Valid Values: [1,…]
  • Importance: low
record.converter.class

Record converter class to convert Kafka records to AWS Lambda payload. Valid entries are ‘JsonKeyValueConverter’ and ‘EscapedJsonKeyValueConverter’. JsonKeyValueConverter converts ‘key’ and ‘value’ to either JSON primitives or objects according to their schema and in case no schema is defined, they are encoded as plain strings. EscapedJsonKeyValueConverter is similar to JsonKeyValueConverter, the only difference is in case no schema is defined, ‘key’ and ‘value’ are encoded as escaped json strings. For more information, please take a look at connector documentation.

  • Type: string
  • Default: JsonKeyValueConverter
  • Importance: low

How should we handle errors?

behavior.on.error

The connector’s behavior if the execution of lambda function returns an error. This setting is applicable only when ‘AWS Lambda invocation type’ is set to ‘sync’ mode. Valid options are ‘log’, ‘fail’ and ‘ignore’. ‘log’ logs the error message in error-<connector-id> topic and continues processing, ‘fail’ stops the connector in case of an error and ‘ignore’ continues to process next set of records.

  • Type: string
  • Default: log
  • Importance: low

Number of tasks for this connector

tasks.max
  • Type: int
  • Valid Values: [1,…]
  • Importance: high

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.

../_images/topology.png