> **Experimental**
>
> `@aws-cdk/aws-s3tables-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# TableBucketEncryption

Controls Server Side Encryption (SSE) for this TableBucket.

- Stability: [Experimental](/cdk/api/stability.html)
- Source: [`lib/table-bucket.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/@aws-cdk/aws-s3tables-alpha/lib/table-bucket.ts#L191)

## Example

TypeScript:

```ts
// Provide a user defined KMS Key:
const key = new kms.Key(scope, 'UserKey', {});
const encryptedBucket = new TableBucket(scope, 'EncryptedTableBucket', {
    tableBucketName: 'table-bucket-1',
    encryption: TableBucketEncryption.KMS,
    encryptionKey: key,
});
// This account principal will also receive kms:Decrypt access to the KMS key
encryptedBucket.grantRead(new iam.AccountPrincipal('123456789012'), '*');

// Use S3 managed server side encryption (default)
const encryptedBucketDefault = new TableBucket(scope, 'EncryptedTableBucketDefault', {
    tableBucketName: 'table-bucket-3',
    encryption: TableBucketEncryption.S3_MANAGED, // Uses AES-256 encryption by default
});
```

Python:

```python
# Provide a user defined KMS Key:
key = kms.Key(scope, "UserKey")
encrypted_bucket = TableBucket(scope, "EncryptedTableBucket",
    table_bucket_name="table-bucket-1",
    encryption=TableBucketEncryption.KMS,
    encryption_key=key
)
# This account principal will also receive kms:Decrypt access to the KMS key
encrypted_bucket.grant_read(iam.AccountPrincipal("123456789012"), "*")

# Use S3 managed server side encryption (default)
encrypted_bucket_default = TableBucket(scope, "EncryptedTableBucketDefault",
    table_bucket_name="table-bucket-3",
    encryption=TableBucketEncryption.S3_MANAGED
)
```

Java:

```java
// Provide a user defined KMS Key:
Key key = Key.Builder.create(scope, "UserKey").build();
TableBucket encryptedBucket = TableBucket.Builder.create(scope, "EncryptedTableBucket")
        .tableBucketName("table-bucket-1")
        .encryption(TableBucketEncryption.KMS)
        .encryptionKey(key)
        .build();
// This account principal will also receive kms:Decrypt access to the KMS key
encryptedBucket.grantRead(new AccountPrincipal("123456789012"), "*");

// Use S3 managed server side encryption (default)
TableBucket encryptedBucketDefault = TableBucket.Builder.create(scope, "EncryptedTableBucketDefault")
        .tableBucketName("table-bucket-3")
        .encryption(TableBucketEncryption.S3_MANAGED)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.AWS.S3Tables.Alpha
// Provide a user defined KMS Key:
var key = new Key(scope, "UserKey", new KeyProps { });
var encryptedBucket = new TableBucket(scope, "EncryptedTableBucket", new TableBucketProps {
    TableBucketName = "table-bucket-1",
    Encryption = TableBucketEncryption.KMS,
    EncryptionKey = key
});
// This account principal will also receive kms:Decrypt access to the KMS key
encryptedBucket.GrantRead(new AccountPrincipal("123456789012"), "*");

// Use S3 managed server side encryption (default)
var encryptedBucketDefault = new TableBucket(scope, "EncryptedTableBucketDefault", new TableBucketProps {
    TableBucketName = "table-bucket-3",
    Encryption = TableBucketEncryption.S3_MANAGED
});
```

Golang:

```go
// Provide a user defined KMS Key:
key := kms.NewKey(*scope, jsii.String("UserKey"), &KeyProps{
})
encryptedBucket := awscdkawss3tablesalpha.NewTableBucket(*scope, jsii.String("EncryptedTableBucket"), &TableBucketProps{
	TableBucketName: jsii.String("table-bucket-1"),
	Encryption: *awscdkawss3tablesalpha.TableBucketEncryption_KMS,
	EncryptionKey: key,
})
// This account principal will also receive kms:Decrypt access to the KMS key
encryptedBucket.grantRead(iam.NewAccountPrincipal(jsii.String("123456789012")), jsii.String("*"))

// Use S3 managed server side encryption (default)
encryptedBucketDefault := awscdkawss3tablesalpha.NewTableBucket(*scope, jsii.String("EncryptedTableBucketDefault"), &TableBucketProps{
	TableBucketName: jsii.String("table-bucket-3"),
	Encryption: *awscdkawss3tablesalpha.TableBucketEncryption_S3_MANAGED,
})
```

## Members

| Member | Description |
| --- | --- |
| `KMS` | Use a customer defined KMS key for encryption If `encryptionKey` is specified, this key will be used, otherwise, one will be defined. |
| `S3_MANAGED` | Use S3 managed encryption keys with AES256 encryption. |

## Referenced by

- [`TableBucketProps`](/v2/docs/@aws-cdk_aws-s3tables-alpha.TableBucketProps).encryption
