Review DocumentDB encryption key management

Choose a KMS key that meets your key-management requirements.

Description

Both examples encrypt the DocumentDB cluster. Choose a customer-managed KMS key if you need to control the key policy and deletion schedule.

Potential impact

Losing access to the key can interrupt the cluster and prevent recovery of snapshots encrypted with it.

Remediation

For a new cluster, set kms_key_id to the approved customer-managed key ARN. To rekey an existing cluster, copy a snapshot using the new key and restore it under a different cluster identifier. Once the new cluster is available, create its instances. Verify the data and application connections before switching traffic.

Examples

The excerpts keep storage_encrypted = true and change the selected key from alias/aws/rds to alias/myAlias. Set the latter to an existing customer-managed key alias.

Before

hcl
data "aws_kms_key" "example" {
  key_id = "alias/aws/rds"
}

resource "aws_docdb_cluster" "example" {
  cluster_identifier = "my-docdb-cluster-test2"
  engine             = "docdb"
  storage_encrypted  = true
  kms_key_id         = data.aws_kms_key.example.arn
}

After

hcl
data "aws_kms_key" "example" {
  key_id = "alias/myAlias"
}

resource "aws_docdb_cluster" "example" {
  cluster_identifier = "my-docdb-cluster-test2"
  engine             = "docdb"
  storage_encrypted  = true
  kms_key_id         = data.aws_kms_key.example.arn
}

References