AWS Lambda Sink Connector for Confluent Cloud

The fully-managed AWS Lambda Sink connector for Confluent Cloud pulls records from one or more Apache Kafka® topics, converts them to JSON, and executes an AWS Lambda function. 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 Asynchronous invocation.

Note

Features

The AWS Lambda Sink connector provides the following features:

  • Supports multiple Lambda functions: The connector supports a single AWS Lambda function or multiple Lambda functions.

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

  • Backward compatibility: The API for this connector is compatible with earlier versions.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect Usage Examples 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.

    Confluent Cloud is available through the AWS Marketplace or directly from Confluent.

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

    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. To use a set of public egress IP addresses, see Public Egress IP Addresses for Confluent Cloud Connectors.

  • 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 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 3: Select your connector

Click the AWS Lambda Sink connector card.

AWS Lambda Sink Connector Card

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 topics 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>

To quickly identify results that are specific to the AWS Lambda function, a message header is included that provides the AWS Lambda function name. Search for the function name in either topic to identify results for the function.

For configuration validation failure or system lag issues, see Troubleshooting.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect Usage Examples section.

Tip

When you launch a connector, a Dead Letter Queue topic is automatically created. See View Connector Dead Letter Queue Errors in Confluent Cloud 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 an example configuration. For two additional examples, see Configuration JSON Examples.

{
  "connector.class": "LambdaSink",
  "name": "LambdaSinkConnector_0",
  "topics": "topic_aws_lambda_1",
  "input.data.format": "JSON",
  "kafka.auth.mode": "KAFKA_API_KEY",
  "kafka.api.key": "****************",
  "kafka.api.secret": "*************************************************",
  "aws.access.key.id": "****************",
  "aws.secret.access.key": "********************************************",
  "aws.lambda.configuration.mode": "single",
  "aws.lambda.function.name": "lambda-test",
  "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.configuration.mode": The mode in which to run the connector. Options are multiple to invoke multiple AWS Lambda functions or single (the default) to invoke a single function. One connector instance can support a maximum of 10 functions.

  • "aws.lambda.function.name": The AWS Lambda function to invoke for single configuration mode.

  • "aws.lambda.topic2function.map": A map of Kafka topics to AWS Lambda functions for multiple configuration mode. Enter the map as comma- separated tuples. For example: <topic-1>;<function-1>,<topic-2>;<function-2>,.... You can map a maximum of three functions to a single topic.

  • "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 Asynchronous 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 the 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 cluster create --config-file <file-name>.json

For example:

confluent connect cluster create --config-file 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 cluster 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>

To quickly identify results that are specific to the AWS Lambda function, a message header is included that provides the AWS Lambda function name. Search for the function name in either topic to identify results for the function.

For configuration validation failure or system lag issues, see Troubleshooting.

For more information and examples to use with the Confluent Cloud API for Connect, see the Confluent Cloud API for Connect Usage Examples section.

Tip

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

Configuration JSON Examples

Select the following tabs for additional configuration examples.

{
  "connector.class": "LambdaSink",
  "name": "LambdaSinkConnector_0",
  "topics": "topic_aws_lambda_1,topic_aws_lambda_2",
  "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": "lambda-test",
  "aws.lambda.configuration.mode": "single",
  "aws.lambda.invocation.type": "sync",
  "behavior.on.error": "fail",
  "tasks.max": "1"
}

Troubleshooting

Review the following if the connector fails validation or seems to be lagging.

Validation failure

When you launch a connector using a configuration JSON file, the configuration is validated for the following conditions:

  • The configuration properties aws.lambda.function.name and aws.lambda.topic2function.map properties cannot be used in the same connector configuration.
  • If the configuration property aws.lambda.configuration.mode is set to single, then only aws.lambda.function.name can be used.
  • If the configuration property aws.lambda.configuration.mode is set to multiple, then only aws.lambda.topic2function.map can be used.
  • A maximum of 10 functions can be used with a single connector.
  • A maximum of three functions can be mapped to one Kafka topic.

System lag

To reduce system lag, try the following:

  • Increase the number of connector tasks. More tasks may improve performance.
  • If the data is not balanced or partitioned properly, you can decrease the number of topics or topic-to-function mapping and create another connector.

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, 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

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

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.configuration.mode

The mode in connector is configured to invoke a single AWS Lambda function or multiple Lambda functions

  • Type: string
  • Default: single
  • Importance: high
aws.lambda.function.name

The AWS Lambda function to invoke.

  • Type: string
  • Importance: high
aws.lambda.topic2function.map

Map of Kafka topics to Lambda functions. Format: comma-separated tuples, e.g. <topic-1>;<function-1>,<topic-2>;<function-2>,…

  • Type: list
  • 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
aws.lambda.socket.timeout

The socket timeout in milliseconds for the AWS Lambda client. This is the amount of time the client will wait for a response from the AWS Lambda service. The default value is 50000 milliseconds. Minimum value is 1000 milliseconds. Maximum value is 600000 milliseconds.

  • Type: int
  • Default: 50000
  • Valid Values: [1000,…,600000]
  • 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

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.

    ../_images/topology.png
  • Try Confluent Cloud on AWS Marketplace with $1000 of free usage for 30 days, and pay as you go. No credit card is required.