

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# AWS KMS 搭配 Amazon Redshift 資料 API 使用
<a name="data-api-kms"></a>

當您使用客戶受管金鑰加密 Amazon Redshift 叢集或 Redshift Serverless 工作群組時，Amazon Redshift Data API 會使用相同的客戶受管金鑰來存放和加密您的查詢和結果。

資料 API 預設會加密您的資料，以保護敏感資訊，例如查詢文字和查詢結果。它會針對此保護使用 擁有 AWS 的 AWS KMS 加密金鑰。

當您保護敏感資料時，靜態資料的預設加密可減少操作開銷和複雜性。此方法可協助您建置符合嚴格加密合規和法規要求的安全應用程式。

## 在 中使用授予 AWS KMS
<a name="data-api-kms-grants"></a>

資料 API 需要授予才能使用客戶受管金鑰。

當您`BatchExecuteStatement`針對使用客戶受管金鑰加密的叢集呼叫 `ExecuteStatement`或 時，Amazon Redshift 會透過傳送[https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html](https://docs.aws.amazon.com/kms/latest/APIReference/API_CreateGrant.html)請求至 來代表您建立授予 AWS KMS。 AWS KMS 使用授予來授予資料 API 存取您帳戶中的 KMS 金鑰。

資料 API 需要授予 ，才能將客戶受管金鑰用於下列操作：
+ 傳送[https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html](https://docs.aws.amazon.com/kms/latest/APIReference/API_Encrypt.html)請求至 AWS KMS ，以使用客戶受管金鑰加密查詢中繼資料。
+ 傳送[https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html](https://docs.aws.amazon.com/kms/latest/APIReference/API_GenerateDataKey.html)請求至 AWS KMS ，以產生由客戶受管金鑰加密的資料金鑰。
+ 將[https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html](https://docs.aws.amazon.com/kms/latest/APIReference/API_Decrypt.html)請求傳送至 AWS KMS 以解密加密的資料金鑰，以便他們可以加密您的資料。

您可以隨時撤銷授予的存取權，或移除客戶受管金鑰的 Amazon Redshift 存取權。如果您這麼做，資料 API 就無法再存取客戶受管金鑰加密的資料，這會影響依賴該資料的操作。例如，如果您在撤銷授予後嘗試擷取查詢結果或追蹤查詢狀態，資料 API 會傳回 `AccessDeniedException`。

## 客戶受管金鑰的金鑰政策
<a name="data-api-kms-policy"></a>

金鑰政策會控制客戶受管金鑰的存取權限。每個客戶受管金鑰都必須只有一個金鑰政策，其中包含決定誰可以使用金鑰及其使用方式的陳述式。在建立客戶受管金鑰時，可以指定金鑰政策。如需更多資訊，請參閱 *AWS Key Management Service 開發人員指南*中的[客戶受管金鑰](https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-mgn-key)。

若要搭配資料 API 使用客戶受管金鑰，您必須先允許存取 Amazon Redshift。金鑰政策中必須允許下列 API 操作：
+ `kms:CreateGrant`：新增客戶受管金鑰的授權。授予控制對指定 AWS KMS 金鑰的存取，允許存取 Amazon Redshift 所需的授予操作。如需詳細資訊，請參閱[在 中使用授予 AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/grants.html#terms-grant-operations)。

以下是金鑰政策範例：

```
"Statement":[
   {
      "Sid":"Allow access to principals authorized to use Amazon Redshift",
      "Effect":"Allow",
      "Principal":{
         "AWS":"*"
      },
      "Action":[
         "kms:DescribeKey",
         "kms:CreateGrant"
      ],
      "Resource":"*",
      "Condition":{
         "StringEquals":{
            "kms:ViaService":"redshift.amazonaws.com",
            "kms:CallerAccount":"111122223333"
         }
      }
   },
   {
      "Sid":"AllowKeyAdministratorsAccess",
      "Effect":"Allow",
      "Principal":{
         "AWS":"arn:aws:iam::111122223333:role/ExampleAdminRole"
      },
      "Action":"kms:*",
      "Resource":"*"
   },
   {
      "Sid":"AllowKeyUseForExampleRole",
      "Effect":"Allow",
      "Principal":{
         "AWS":"arn:aws:iam::111122223333:role/ExampleUserRole"
      },
      "Action":[
         "kms:Encrypt",
         "kms:Decrypt",
         "kms:ReEncrypt*",
         "kms:GenerateDataKey*",
         "kms:DescribeKey"
      ],
      "Resource":"*"
   }
]
```

## 資料 API 加密內容
<a name="data-api-kms-encryption"></a>

加密內容是選用的一組金鑰/值對，其中包含有關資料的其他內容資訊。 AWS KMS 會使用加密內容作為額外的已驗證資料，以支援已驗證的加密。當您在加密資料的請求中包含加密內容時， 會將加密內容 AWS KMS 繫結至加密的資料。若要解密資料，您必須在請求中包含相同的加密內容。

資料 API 在所有已佈建叢集 AWS KMS 的密碼編譯操作中使用相同的三個加密內容金鑰/值對：
+ `aws:redshift:arn` – 叢集的 Amazon Resource Name (ARN)
+ `aws:redshift:createtime` – 您請求建立叢集時的時間戳記
+ `serviceName` – `RedshiftDataAPI`

```
"EncryptionContextSubset": {
    "aws:redshift:arn": "arn:aws:redshift:us-east-1:123456789012:cluster:redshift-cluster",
    "aws:redshift:createtime": "20250815T0000Z",
    "serviceName": "RedshiftDataAPI",
}
```

資料 API 在所有 AWS KMS 無伺服器工作群組的密碼編譯操作中使用兩個加密內容金鑰/值對：
+ `aws:redshift-serverless:arn` – 命名空間的 Amazon Resource Name (ARN)
+ `serviceName` – RedshiftDataAPI

```
"EncryptionContextSubset": {
    "aws:redshift-serverless:arn": "arn:aws:redshift-serverless:us-east-1:123456789012:namespace:12345678-1234-1234-1234-123456789012",
    "serviceName": "RedshiftDataAPI"
}
```

如需加密的詳細資訊，請參閱 [的密碼編譯詳細資訊簡介 AWS KMS](https://docs.aws.amazon.com/kms/latest/cryptographic-details/intro.html)。如需 Amazon Redshift 和 AWS KMS 整合的詳細資訊，請參閱 [Amazon Redshift 如何使用 AWS KMS](https://docs.aws.amazon.com/kms/latest/developerguide/services-redshift.html)。