

# Data rules for integrations with Amazon S3 Tables

**Important**  
This is preview documentation for the Aurora PostgreSQL integration with Amazon S3 Tables. Before using this capability, review the Betas and Previews terms in the [AWS Service Terms](https://aws.amazon.com/service-terms/).

Data rules control which data the Aurora PostgreSQL integration with Amazon S3 Tables replicates from the source DB cluster to the target table bucket. Rather than replicate the whole DB cluster, you write rules that include or exclude databases, schemas, tables, and columns. The data rules also set the target prefix for the namespaces that the integration creates.

You can set data rules with the AWS Management Console, the AWS CLI, or the Amazon RDS API. In the AWS CLI, pass the rules to `--data-rules` on both `create-integration` and `modify-integration`. For more information, see [Creating an integration with the AWS CLI](s3tables-integration.creating.md#s3tables-integration.creating.cli) and [Changing data rules](s3tables-integration.modifying.md#s3tables-integration.modifying.data-rules).

For an Amazon S3 Tables target, `create-integration` and `modify-integration` do not accept `--data-filter`. zero-ETL integrations use data filters instead. For more information, see [Data filtering for Aurora zero-ETL integrations](zero-etl.filtering.md).

You cannot change the `TargetPrefix`. When you modify the data rules, resubmit the same prefix.

**Topics**
+ [Data rules syntax](#s3tables-integration.data-rules.syntax)
+ [Replicating everything](#s3tables-integration.data-rules.everything)
+ [Replicating selected databases, schemas, or tables](#s3tables-integration.data-rules.selected)
+ [Excluding sensitive columns](#s3tables-integration.data-rules.exclude-columns)
+ [Including only specific columns](#s3tables-integration.data-rules.include-columns)
+ [Using more than one integration with a table bucket](#s3tables-integration.data-rules.multiple)

## Data rules syntax
<a name="s3tables-integration.data-rules.syntax"></a>

A data rules configuration is a JSON array of rules. Each rule matches objects by `Database`, `Schema`, and `Table`, and sets one or more values under `Properties` for the objects that it matches.

The following table describes the fields of a rule.


| Field | Value | Description | 
| --- | --- | --- | 
| Database | A name, \*, or a name with \* at the start, the end, or both (for example, sales\*) | The source database that the rule matches. \* matches all. A \* inside a name is not allowed. Names are case-sensitive. | 
| Schema | A name, \*, or a name with \* at the start, the end, or both | The source schema that the rule matches. \* matches all. The same rules apply as for Database. | 
| Table | A name, \*, or a name with \* at the start, the end, or both | The source table that the rule matches. \* matches all. The same rules apply as for Database. | 
| Properties.TargetPrefix | 1 to 64 characters: a lowercase letter, then lowercase letters, digits, or underscores. It cannot start with aws. | The prefix for the namespaces in the target table bucket. Set it in exactly one rule whose Database, Schema, and Table are all \*. It must be unique in the target table bucket and must not create overlapping namespace names with other integrations' prefixes (see [Using more than one integration with a table bucket](#s3tables-integration.data-rules.multiple)). | 
| Properties.IncludeColumns | An array of column names | The columns to include for the matched tables. ["\*"] includes all columns. Column entries follow the same naming, case-sensitivity, and wildcard rules as Database. | 
| Properties.ExcludeColumns | An array of column names | The columns to exclude for the matched tables. ["\*"] excludes all columns, so the matched tables are not replicated unless a later rule includes columns for them again. Column entries follow the same naming, case-sensitivity, and wildcard rules as Database. | 

### How the integration applies rules
<a name="s3tables-integration.data-rules.syntax.order"></a>

When you create an integration, and each time that you change its data rules, Aurora adds a default rule before your rules. The default rule matches every database, schema, and table (`*.*.*`) and includes all columns (`"IncludeColumns": ["*"]`). Your rules always come after it, so everything is included unless one of your rules excludes it. The default rule is not returned when you describe the integration, and it does not count toward the limit on the number of rules.

The integration then applies your rules in order, from the first rule to the last. For each rule that matches a table, the integration first removes the columns listed in `ExcludeColumns`. It then adds back the columns listed in `IncludeColumns`. Because the rules run in sequence, a later rule can override an earlier one. Duplicate or overlapping rules are allowed and follow the same order. A table whose columns are all excluded is not replicated.

For example, suppose that you enter the following rules, expecting only the `audit_log` table to replicate:

```json
[
  {"Database": "*", "Schema": "*", "Table": "*", "Properties": {"TargetPrefix": "{{my_prefix}}"}},
  {"Database": "*", "Schema": "*", "Table": "{{audit_log}}", "Properties": {"IncludeColumns": ["*"]}}
]
```

Aurora applies these rules after its default rule:

```json
[
  {"Database": "*", "Schema": "*", "Table": "*", "Properties": {"IncludeColumns": ["*"]}},
  {"Database": "*", "Schema": "*", "Table": "*", "Properties": {"TargetPrefix": "{{my_prefix}}"}},
  {"Database": "*", "Schema": "*", "Table": "{{audit_log}}", "Properties": {"IncludeColumns": ["*"]}}
]
```

Every table replicates, because the default rule includes everything and none of your rules excludes anything.

To replicate only `audit_log`, exclude everything first. Set `"ExcludeColumns": ["*"]` on the rule that carries the `TargetPrefix`, keep that rule first, and then include `audit_log`. Name the table's database and schema exactly, because a `*` there matches a table named `audit_log` in every database and schema:

```json
[
  {"Database": "*", "Schema": "*", "Table": "*", "Properties": {"TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"]}},
  {"Database": "{{appdb}}", "Schema": "{{public}}", "Table": "{{audit_log}}", "Properties": {"IncludeColumns": ["*"]}}
]
```

Aurora's default rule includes every table, your first rule then excludes every table, and your second rule includes `appdb.public.audit_log` again. So only that table replicates.

### Where to set the target prefix
<a name="s3tables-integration.data-rules.syntax.prefix"></a>

You can set `TargetPrefix` on only one rule, and that rule must have `Database`, `Schema`, and `Table` all set to `*`. A configuration can have other `*.*.*` rules, such as a rule that excludes a column everywhere, but they cannot set `TargetPrefix`. Within `Properties`, the only keys that you can set are `TargetPrefix`, `IncludeColumns`, and `ExcludeColumns`.

### Valid names and wildcards
<a name="s3tables-integration.data-rules.syntax.names"></a>

Each `Database`, `Schema`, and `Table` value, and each `IncludeColumns` or `ExcludeColumns` entry, can be up to 256 characters. A value is one of the following:
+ An exact name, such as `orders`.
+ A single `*`, which matches everything.
+ A name with one `*` at the start, the end, or both, such as `orders_*` or `*_pii`.

A `*` in the middle of a name, or `**`, is not allowed.

### Limits
<a name="s3tables-integration.data-rules.syntax.limits"></a>

A configuration can have up to 500 rules, and each column list can have up to 100 entries.

## Replicating everything
<a name="s3tables-integration.data-rules.everything"></a>

By default, the integration replicates every database, schema, and table that it supports. The following data rules set the target prefix and replicate everything:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}" }
  }
]
```

When you describe a specific integration (with `--integration-identifier`), the response returns your data rules exactly as you submitted them. It does not show the default rule that Aurora adds before your rules. When you list integrations without an identifier, the response does not include data rules.

## Replicating selected databases, schemas, or tables
<a name="s3tables-integration.data-rules.selected"></a>

Every data rules configuration has one `*.*.*` rule that carries the `TargetPrefix`. If that rule also sets `ExcludeColumns`, make it the first rule, because a later rule overrides an earlier one. The `TargetPrefix` rule includes all databases, schemas, and tables by default, so the integration replicates everything unless you restrict it. Because all objects are included by default, adding a rule that matches a specific database, schema, or table (for example, with `IncludeColumns` set to `["*"]`) does not limit replication to that object. You must first exclude everything, as described next.

To replicate a subset of your DB cluster, set `ExcludeColumns` to `["*"]` on the `*.*.*` rule to exclude all objects. Then add one or more rules that set `IncludeColumns` to `["*"]` for the databases, schemas, or tables that you want to replicate.

To replicate a single database, add an include rule for it after the exclude rule. This example replicates every schema and table in the `sales` database:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "*",
    "Table": "*",
    "Properties": { "IncludeColumns": ["*"] }
  }
]
```

To replicate one schema, name it in `Schema` as well. This example replicates every table in the `public` schema of `sales`:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{public}}",
    "Table": "*",
    "Properties": { "IncludeColumns": ["*"] }
  }
]
```

To replicate specific tables, add one include rule for each table. This example replicates only `orders` and `customers`:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{public}}",
    "Table": "{{orders}}",
    "Properties": { "IncludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{public}}",
    "Table": "{{customers}}",
    "Properties": { "IncludeColumns": ["*"] }
  }
]
```

## Excluding sensitive columns
<a name="s3tables-integration.data-rules.exclude-columns"></a>

Every table starts with all of its columns included. To keep a sensitive column out of the target, exclude it with a data rule. A column that is not replicated cannot be read from the target. If you exclude a column after it has replicated, earlier Apache Iceberg snapshots still contain it. For more information, see [Changing data rules](s3tables-integration.modifying.md#s3tables-integration.modifying.data-rules).

**Important**  
Dynamic masking policies that you create with the `pg_columnmask` extension are not applied to replicated data, so a masked column reaches the target unmasked. To keep a masked column out of the target, exclude it with an `ExcludeColumns` data rule in addition to its masking policy. For more information, see [Aurora PostgreSQL pg\_columnmask data movement scenarios](AuroraPostgreSQL.Security.DynamicMasking.DataMovement.md).

This example replicates all tables but excludes the `ssn` column wherever it appears:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}" }
  },
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "ExcludeColumns": ["{{ssn}}"] }
  }
]
```

Column names in data rules are case-sensitive. To exclude both `ssn` and `SSN`, list both. To match variants such as `ssn_last4`, use a wildcard, such as `ssn*`.

**Important**  
Put the rule that excludes sensitive columns last. A later rule with `"IncludeColumns": ["*"]` adds back every column, including one that an earlier rule excluded. Within one rule, `IncludeColumns` is applied after `ExcludeColumns`, so `"IncludeColumns": ["*"], "ExcludeColumns": ["ssn"]` still replicates `ssn`.

The following example replicates the `public` and `billing` schemas of `sales`, and excludes `ssn` and `date_of_birth` from every table:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{public}}",
    "Table": "*",
    "Properties": { "IncludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{billing}}",
    "Table": "*",
    "Properties": { "IncludeColumns": ["*"] }
  },
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "ExcludeColumns": ["{{ssn}}", "{{date_of_birth}}"] }
  }
]
```

To confirm that an excluded column is not replicated, list the target table's columns, and check that the excluded column is not in the list. For example, with the `s3t` catalog from [Querying with Apache Spark](s3tables-integration.querying.md#s3tables-integration.querying.spark), run the following command in `spark-shell`:

```
spark.table("s3t.{{my_prefix_sales}}.{{public_orders}}").columns.foreach(println)
```

For more checks, see [Validating replicated data](s3tables-integration.querying.md#s3tables-integration.querying.validate).

## Including only specific columns
<a name="s3tables-integration.data-rules.include-columns"></a>

To replicate only a few columns of a table, exclude everything on the `*.*.*` rule, and then include only those columns. This example keeps only `id`, `name`, and `amount` from the `reports` table and replicates nothing else:

```json
[
  {
    "Database": "*",
    "Schema": "*",
    "Table": "*",
    "Properties": { "TargetPrefix": "{{my_prefix}}", "ExcludeColumns": ["*"] }
  },
  {
    "Database": "{{sales}}",
    "Schema": "{{public}}",
    "Table": "{{reports}}",
    "Properties": { "IncludeColumns": ["{{id}}", "{{name}}", "{{amount}}"] }
  }
]
```

If an earlier rule already includes every column of the table (for example, a rule that includes the whole database), a later rule with only `IncludeColumns` does not remove the other columns. All columns are still replicated. In that case, put `"ExcludeColumns": ["*"]` and the `IncludeColumns` list in the same rule for that table. Place that rule after the rule that includes the database.

## Using more than one integration with a table bucket
<a name="s3tables-integration.data-rules.multiple"></a>

More than one integration can write to the same table bucket. Give each integration a different `TargetPrefix`. If you reuse a prefix that another integration on the same table bucket already uses, `create-integration` fails with an `InvalidParameterCombination` error: "The TargetPrefix [...] is already used by another integration with the same target table bucket. Specify a different TargetPrefix and retry the request." Because the integration joins the prefix and the database name with an underscore, two different prefixes can still produce the same namespace name. For example, the prefix `acme` with the database `app_db`, and the prefix `acme_app` with the database `db`, both produce `acme_app_db`. Do not use a prefix that, followed by an underscore, is the start of another integration's prefix in the same table bucket. Each integration creates its own namespaces under its prefix and replicates independently.