> ## Documentation Index
> Fetch the complete documentation index at: https://www.artie.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Amazon Kinesis destination: setup and configuration

> Publish change events to your own Amazon Kinesis Data Streams, to one stream for every table or a stream per table, as Debezium JSON in the order each row changed.

## Prerequisites

* Kinesis destinations turned on for your account. Contact Artie to enable them.
* A Kinesis data stream for each stream Artie writes to. Artie doesn't create streams.
* Permission to create an IAM role in the AWS account that owns the streams.
* A source with a dedicated source reader. Kinesis destinations can't use a shared source reader.

Artie reaches Kinesis over its public regional endpoint. Kinesis destinations don't support SSH tunnels or PrivateLink.

## How Artie writes to Kinesis

Artie's reader publishes each change straight to your streams. No separate writer runs between your source and your streams, so the settings Artie's writer applies to other destinations don't apply. See [Limitations](#limitations).

You choose one of two stream layouts:

* **One stream for every table** sends every table's changes to one stream you name.
* **A stream per table** sends each table to its own stream, named `<stream prefix>.<table identifier>`.

With a stream per table, the table identifier depends on the source, the same as a [Kafka destination's topic names](/docs/destinations/kafka#how-artie-writes-to-kafka):

| Source               | Stream name                            |
| -------------------- | -------------------------------------- |
| PostgreSQL           | `<prefix>.<schema>.<table>`            |
| MySQL                | `<prefix>.<database>.<table>`          |
| Microsoft SQL Server | `<prefix>.<database>.<schema>.<table>` |

Kinesis stream names are at most 128 characters of letters, digits, `.`, `_` and `-`. A table whose stream name doesn't fit fails its first write.

## Set up Kinesis as a destination

**Step 1: Create the streams**

In the Kinesis console, create each stream Artie writes to, in the Region you'll enter in Artie. With a stream per table, create one stream for each table in the pipeline.

On-demand capacity mode is the safer choice. Each provisioned shard takes up to 1 MB or 1,000 records per second, and writes over that are throttled. See [Kinesis quotas and limits](https://docs.aws.amazon.com/streams/latest/dev/service-sizes-and-limits.html).

**Step 2: Create a role for Artie**

In the AWS account that owns the streams, create an IAM role. Artie assumes this role to write to your streams. Attach this permission policy:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "kinesis:PutRecords",
        "kinesis:DescribeStreamSummary"
      ],
      "Resource": "arn:aws:kinesis:us-east-1:123456789012:stream/artie*"
    },
    {
      "Effect": "Allow",
      "Action": "kinesis:ListStreams",
      "Resource": "*"
    }
  ]
}
```

Replace the Region `us-east-1`, the account ID `123456789012` and the stream name pattern `artie*` with your own. `kinesis:ListStreams` is only needed with a stream per table, where Artie uses it to verify the role.

If your streams use server-side encryption with a customer managed KMS key, also allow `kms:GenerateDataKey` on that key. See [Permissions to use user-generated KMS keys](https://docs.aws.amazon.com/streams/latest/dev/permissions-user-key-KMS.html).

Then set the role's trust policy to let Artie's AWS principal, `arn:aws:iam::788826912768:user/ci`, assume it with an external ID you choose:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {"AWS": "arn:aws:iam::788826912768:user/ci"},
      "Action": "sts:AssumeRole",
      "Condition": {"StringEquals": {"sts:ExternalId": "EXTERNAL_ID"}}
    }
  ]
}
```

Replace `EXTERNAL_ID` with your external ID. Choose an external ID that is hard to guess. It's 2 to 1,224 characters of letters, digits and `+=,.@:/-_`. On a data plane you run yourself, trust the IAM identity your data plane runs as.

**Step 3: Connect Kinesis in the pipeline setup**

When you create a pipeline, the setup reaches **Choose your destination** after you choose tables.

1. On **Choose your destination**, select **Kinesis**, then select **Continue**.
2. On **Connect Kinesis**, fill in the fields from the table in this step.
3. Select **Verify destination**. Artie shows "Destination verified".
4. Select **Continue**.

**Kinesis** doesn't appear on **Choose your destination** when Kinesis destinations are off for your account or the source uses a shared source reader.

The **Connect Kinesis** step has these fields:

| Field             | What to enter                                                                                                    |
| ----------------- | ---------------------------------------------------------------------------------------------------------------- |
| **AWS region**    | Required. The streams' Region, for example `us-east-1`. Pick one from the list or type any AWS Region code.      |
| **AWS role ARN**  | Required. The role from **Create a role for Artie**, for example `arn:aws:iam::123456789012:role/artie-kinesis`. |
| **External ID**   | Required. The `sts:ExternalId` value in the role's trust policy.                                                 |
| **Streams**       | **One stream for every table** or **A stream per table**.                                                        |
| **Stream name**   | Required for one stream for every table. 1 to 128 letters, digits, `.`, `_` and `-`.                             |
| **Stream prefix** | Required for a stream per table. 1 to 126 letters, digits, `.`, `_` and `-`.                                     |

When Artie verifies the destination, it assumes your role. With one stream for every table, it then checks that the stream exists and is `ACTIVE` or `UPDATING`. With a stream per table, it checks that the role can list streams. Artie writes nothing while verifying, so a missing `kinesis:PutRecords` permission shows up on the first write.

To change these fields on an existing pipeline, select **Edit pipeline**, then open the **Destination: Kinesis** tab.

**Step 4: Deploy the pipeline**

On **Review and deploy**, select **Validate and deploy**. Artie publishes each table's existing rows to its stream as backfill records, and publishes changes as they happen.

With one stream for every table, the pipeline fails at startup if the stream doesn't exist. With a stream per table, a missing stream fails its table's first write.

## Advanced

These sections describe the records Artie publishes and how it handles ordering, failed writes, large records, backfills and billing.

### Record format

Each record is one change to one row. Kinesis records have no key or headers, so the record's data is a JSON object with two fields:

```json
{"key": KEY, "value": VALUE}
```

`KEY` and `VALUE` are the message key and value a [Kafka destination](/docs/destinations/kafka#message-format) publishes for the same change. The key holds the row's primary key. The value is [Debezium](https://debezium.io/documentation/reference/stable/connectors/postgresql.html#postgresql-events)-style JSON with a `schema` and a `payload`.

Read the payload fields like this:

* `op` is `c` for inserts, `u` for updates, `d` for deletes, and `r` for rows from a backfill.
* For a delete, `after` is `null` and `before` holds the deleted row.
* `source.ts_ms` is when the change happened in the source, in milliseconds since the Unix epoch.

The partition key is a SHA-256 hash, in hex, of the table name and the row's primary key. Every change to a row goes to the same shard.

### Ordering and delivery

Artie sends each row's changes in the order they happened. It sends one `PutRecords` request at a time, and a request never holds two changes to the same row.

Delivery is at least once. Make your consumers idempotent, for example by upserting on the record's `key`.

If some records in a request fail, Artie sends only those records again. It retries throttling and other errors that can pass for up to 2 minutes per request. It waits up to 5 seconds between attempts.

Artie fails at once on errors a retry can't fix, such as `AccessDeniedException`, `ResourceNotFoundException` or a KMS key error. Artie only advances its position in your source after Kinesis accepts the records, so a failed write doesn't lose changes.

After an error or a restart, Artie publishes again from its last committed position, so consumers can see some records twice. When a request times out on Artie's side but Kinesis applied it, a row's older record can arrive after a newer one.

### Record size

Artie reads each stream's maximum record size when it first writes to the stream. The default is 1 MiB, and a stream's limit goes up to 10 MiB. The limit counts the record's data and partition key.

Artie skips a larger record and keeps going. It sends a [row skipped](/docs/api/webhooks/row-skipped) webhook event with the table and primary key.

> **Warning:**
>
> Skipped records don't reach your streams. If a table has rows larger than your stream's maximum record size, raise the stream's limit before adding the table.

### Backfills

Kinesis streams can't be emptied before a backfill. When you backfill or restart a backfill, Artie publishes every row again with `op` set to `r`. The new records land after the records already in the stream.

The backfill dialog says "Nothing is deleted first. The backfill is published on top of the existing messages." Consumers see each backfilled row again, so handle `r` like an upsert.

### Monitoring and billing

Artie counts the rows it publishes. Pipeline monitors and charts for a Kinesis destination use those counts and the time from a change in your source to its publish.

Billing counts published inserts, updates, and deletes. Rows from backfills (`op` `r`) aren't billed.

## Limitations

Kinesis destinations differ from other destinations in these ways:

| Limitation                         | Detail                                                                                                                                                                                                                           |
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Writer settings don't apply        | The Dashboard hides history mode, column hashing, column encryption, **Soft-delete rows**, **Drop deleted columns**, **Cast all columns to string** and flush rules. It hides **Skip deletes** unless a table already has it on. |
| Shared source readers              | Not supported. The source reader must be dedicated to the pipeline.                                                                                                                                                              |
| Stream creation                    | Artie doesn't create streams. Create each one before the pipeline writes to it.                                                                                                                                                  |
| Table-level monitors               | Saving one fails with `Table monitors aren't supported for Kinesis destinations. Monitor the whole pipeline instead.`                                                                                                            |
| Emptying streams before a backfill | Streams can't be emptied, dropped, or swapped. See [Backfills](#backfills).                                                                                                                                                      |
| Records over the stream's limit    | Skipped. See [Record size](#record-size).                                                                                                                                                                                        |
| Compression                        | **Message compression** has no effect. Columns set to be compressed are sent uncompressed.                                                                                                                                       |
| Schema change records              | Not published. Artie publishes row changes only. A column's type and presence show up in each record's `schema`.                                                                                                                 |
| SSH tunnels and PrivateLink        | Not supported. Saving a Kinesis connector with PrivateLink fails with `PrivateLink isn't supported for Kinesis`.                                                                                                                 |

## Frequently asked questions

These answers cover duplicate records, missing streams and deletes.

### Why do my consumers see the same record twice?

A write was retried, the pipeline restarted, or a table was backfilled again. Delivery is at least once, so make consumers idempotent. See [Ordering and delivery](#ordering-and-delivery).

### Why is the pipeline failing with a stream that doesn't exist?

The error reads `kinesis stream "<name>" doesn't exist`. In the Kinesis console, create the stream with that exact name in the pipeline's Region. With a stream per table, check the table's name against [the stream names](#how-artie-writes-to-kinesis).

### How do I tell a delete from an update?

Read `op` in the record's `value`. It's `d` for deletes, where `before` holds the deleted row, and `u` for updates.