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

# S3 Tables

> Learn how to configure Amazon S3 Tables as an Iceberg destination in Artie, including table bucket setup and IAM service account permissions.

## Required settings

* Table bucket ARN
* AWS region
* AWS access key ID and secret access key (from the script below)

**Find table bucket ARN**

To find your table bucket ARN, go to your AWS console,  click on S3 and navigate to the table bucket tab.

![S3 table bucket](/docs/assets/destinations/s3tables/table_bucket_arn.webp)

### Creating a service account

The service account will need S3 Tables API access.

**Terraform script**

```hcl
variable "table_bucket_name" {
  type = string
}

variable "service_account_name" {
  type = string
}

// If the S3 Tables bucket is encrypted with KMS. Otherwise, remove the
// kms_key_id, region and account_id variables and the KMS statement below.
variable "kms_key_id" {
  type = string
}

// The Region and AWS account ID of the KMS key.
variable "region" {
  type = string
}

variable "account_id" {
  type = string
}

resource "aws_iam_policy" "s3_tables_policy" {
  name        = "S3TablesPolicy"
  description = "Policy that grants access to S3 tables and related resources"

  policy = jsonencode({
    Version = "2012-10-17",
    Statement = [
      {
        Effect = "Allow",
        Action = [
          "s3tables:CreateTable",
          // DeleteTable is used to drop the staging table after each flush, and to drop a table before a backfill.
          "s3tables:DeleteTable",
          "s3tables:GetTableBucket",
          "s3tables:GetTableMetadataLocation",
          "s3tables:ListTables",
          "s3tables:GetNamespace",
          "s3tables:ListNamespaces",
          // CreateNamespace is only required if you want Artie to create missing namespaces when the pipeline deploys.
          "s3tables:CreateNamespace"
        ],
        Resource = [
          "arn:aws:s3tables:*:*:bucket/${var.table_bucket_name}",
          "arn:aws:s3tables:*:*:bucket/${var.table_bucket_name}/*"
        ]
      },
      {
        Effect = "Allow",
        Action = [
          "s3tables:GetTable",
          "s3tables:GetTableData",
          "s3tables:GetTableMetadataLocation",
          "s3tables:PutTableData",
          "s3tables:UpdateTableMetadataLocation"
        ],
        Resource = [
          "arn:aws:s3tables:*:*:bucket/${var.table_bucket_name}/table/*"
        ]
      },
      // If the S3 Tables bucket is encrypted with KMS:
      {
        Effect = "Allow",
        Action = [
          "kms:GenerateDataKey",
          "kms:Decrypt",
        ],
        Resource = [
          "arn:aws:kms:${var.region}:${var.account_id}:key/${var.kms_key_id}",
        ]
      }
    ]
  })
}

resource "aws_iam_user" "s3_tables_user" {
  name = var.service_account_name
  path = "/"
}

resource "aws_iam_user_policy_attachment" "s3_tables_user_policy_attachment" {
  user       = aws_iam_user.s3_tables_user.name
  policy_arn = aws_iam_policy.s3_tables_policy.arn
}

resource "aws_iam_access_key" "s3_tables_user_key" {
  user = aws_iam_user.s3_tables_user.name
}

output "aws_access_key_id" {
  value     = aws_iam_access_key.s3_tables_user_key.id
  sensitive = true
}

output "aws_secret_access_key" {
  value     = aws_iam_access_key.s3_tables_user_key.secret
  sensitive = true
}
```

### Naming rules

S3 Tables only accepts certain table and namespace names. When you validate or deploy the pipeline, Artie checks every destination table name, history table name and namespace against these rules. A name that breaks one stops validation with an error that names it.

| Rule                                            | Applies to            | Error                                                                                                                            |
| ----------------------------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| Lowercase letters, numbers and underscores only | Tables and namespaces | `table name "<name>" has a character S3 Tables doesn't allow; S3 Tables only allows lowercase letters, numbers, and underscores` |
| Starts with a letter or number                  | Tables and namespaces | `table name "<name>" must start with a letter or number`                                                                         |
| 255 bytes or fewer                              | Tables and namespaces | `table name "<name>" exceeds maximum length of 255 bytes`                                                                        |
| Ends with a letter or number                    | Namespaces            | `namespace "<name>" must end with a letter or number`                                                                            |
| Doesn't start with `aws`                        | Namespaces            | `namespace "<name>" can't start with "aws"`                                                                                      |

Namespace errors start with `namespace` instead of `table name`. Artie lowercases namespaces before it checks them, so a source schema named `Sales` passes as `sales`.

To fix a table name error, set a valid **Destination table name** in that table's advanced settings, then validate again. To fix a namespace error, change the destination namespace in the pipeline's destination settings. See the [S3 Tables naming rules](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-buckets-naming.html).

### Table format

S3 Tables pipelines create Iceberg v2 tables. The **Table format** setting stays on **Iceberg v2**, since Athena and StarRocks can't read v3 tables yet. A pipeline saved with v3 stops validation with `S3 Tables only supports Iceberg v2 tables, since Athena and StarRocks can't read v3. Set the table format to v2`. Switch **Table format** to **Iceberg v2** and deploy again.