

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

# 使用 AWS CloudFormation 範本自動化 AWS Glue 中的加密強制執行 AWS CloudFormation
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template"></a>

*Diogo Guedes，Amazon Web Services*

## 總結
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-summary"></a>

此模式說明如何使用 AWS CloudFormation 範本在 AWS Glue 中設定和自動化加密強制執行。 AWS CloudFormation 範本會建立強制執行加密所需的所有必要組態和資源。這些資源包括初始組態、Amazon EventBridge 規則建立的預防性控制，以及 AWS Lambda 函數。

## 先決條件和限制
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ 部署 CloudFormation 範本及其資源的許可

**限制**

此安全控制是區域性的。您必須在要在 AWS Glue 中設定加密強制執行的每個 AWS 區域中部署安全控制。

## Architecture
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-architecture"></a>

**目標技術堆疊**
+ Amazon CloudWatch Logs （來自 AWS Lambda)
+ Amazon EventBridge 規則
+ AWS CloudFormation 堆疊
+ AWS CloudTrail
+ AWS Identity and Access Management (IAM) 受管角色和政策
+ AWS Key Management Service (AWS KMS)
+ AWS KMS 別名
+ AWS Lambda 功能
+ AWS Systems Manager 參數存放區

**目標架構**

下圖顯示如何在 AWS Glue 中自動化加密強制執行。

![圖表顯示如何使用 CloudFormation 範本自動化 AWS Glue 中的加密強制執行。](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/images/pattern-img/d50d0659-5592-44d0-8fcb-7a2983712640/images/272a7fb2-ecbc-41f7-a556-d555e4e39a59.png)


該圖顯示以下工作流程：

1. [CloudFormation 範本](https://github.com/aws-samples/aws-custom-guardrail-event-driven/blob/main/CloudFormation/aws-custom-guardrail-event-driven.yaml)會建立所有資源，包括 AWS Glue 中加密強制執行的初始組態和偵測控制。

1. EventBridge 規則會偵測加密組態中的狀態變更。

1. 透過 CloudWatch Logs 叫用 Lambda 函數進行評估和記錄。對於不合規偵測，參數存放區會使用 AWS KMS 金鑰的 Amazon Resource Name (ARN) 復原。服務會修復為啟用加密的合規狀態。

**自動化和擴展**

如果您使用的是 [AWS Organizations](https://aws.amazon.com/organizations/)，則可以使用 [AWS CloudFormation StackSets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html) 在多個帳戶中部署此範本，其中您想要在 AWS Glue 中啟用加密強制執行。

## 工具
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-tools"></a>
+ [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 可協助您即時監控 AWS 資源的指標，以及您在 AWS 上執行的應用程式。
+ [Amazon EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-what-is.html) 是一種無伺服器事件匯流排服務，可協助您將應用程式與來自各種來源的即時資料連線。例如，Lambda 函數、使用 API 目的地的 HTTP 調用端點，或其他 AWS 帳戶中的事件匯流排。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html) 可協助您設定 AWS 資源、快速一致地佈建資源，以及在整個 AWS 帳戶和區域的生命週期進行管理。
+ [AWS CloudTrail](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) 可協助您啟用 AWS 帳戶的營運和風險稽核、控管和合規。
+ [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html) 是全受管的擷取、轉換和載入 (ETL) 服務。它可協助您可靠地分類、清理、擴充和移動資料存放區和資料串流之間的資料。
+ [AWS Key Management Service (AWS KMS)](https://docs.aws.amazon.com/kms/latest/developerguide/overview.html) 可協助您建立和控制密碼編譯金鑰，以協助保護您的資料。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一種運算服務，可協助您執行程式碼，而無需佈建或管理伺服器。它只會在需要時執行程式碼並自動擴展，因此您只需按使用的運算時間付費。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可協助您管理在 AWS 雲端中執行的應用程式和基礎設施。它可簡化應用程式和資源管理、縮短偵測和解決操作問題的時間，並協助您大規模安全地管理 AWS 資源。

**Code**

此模式的程式碼可在 GitHub [aws-custom-guardrail-event-driven](https://github.com/aws-samples/aws-custom-guardrail-event-driven/blob/main/CloudFormation/aws-custom-guardrail-event-driven.yaml) 儲存庫中使用。

## 最佳實務
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-best-practices"></a>

AWS Glue 支援靜態資料加密，以便在 [ AWS Glue 中編寫任務](https://docs.aws.amazon.com/glue/latest/dg/author-job-glue.html)[，並使用開發端點開發指令碼](https://docs.aws.amazon.com/glue/latest/dg/dev-endpoint.html)。

請考慮下列最佳實務：
+ 設定 ETL 任務和開發端點，以使用 AWS KMS 金鑰寫入靜態加密的資料。
+ 使用您透過 [AWS KMS 管理的金鑰，加密存放在 AWS Glue Data Catalog](https://docs.aws.amazon.com/glue/latest/dg/components-overview.html#data-catalog-intro) 中的中繼資料。
+ 使用 AWS KMS 金鑰來加密任務書籤，以及[爬蟲程式](https://docs.aws.amazon.com/glue/latest/dg/add-crawler.html)和 ETL 任務所產生的日誌。

## 史詩
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-epics"></a>

### 啟動 CloudFormation 範本
<a name="launch-the-cloudformation-template"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 部署 CloudFormation 範本。 | 從 GitHub [儲存庫](https://github.com/aws-samples/aws-custom-guardrail-event-driven/blob/main/CloudFormation/aws-custom-guardrail-event-driven.yaml)下載`aws-custom-guardrail-event-driven.yaml`範本，然後[部署](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deploy/index.html)範本。`CREATE_COMPLETE` 狀態表示您的範本已成功部署。範本不需要輸入參數。 | 雲端架構師 | 

### 驗證 AWS Glue 中的加密設定
<a name="verify-the-encryption-settings-in-aws-glue"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 檢查 AWS KMS 金鑰組態。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template.html) | 雲端架構師 | 

### 測試加密強制執行
<a name="test-the-encryption-enforcement"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 識別 CloudFormation 中的加密設定。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template.html) | 雲端架構師 | 
| 將佈建的基礎設施切換為不合規狀態。 | [See the AWS documentation website for more details](http://docs.aws.amazon.com/zh_tw/prescriptive-guidance/latest/patterns/automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template.html)在您清除核取方塊後，護欄會偵測 AWS Glue 中的不合規狀態，然後透過自動修復加密設定錯誤來強制執行合規。因此，在您重新整理頁面之後，應該再次選取加密核取方塊。 | 雲端架構師 | 

## 相關資源
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template-resources"></a>
+ [在 AWS CloudFormation 主控台上建立堆疊](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html) (AWS CloudFormation 文件）
+ [使用 AWS CloudTrail 建立在 AWS API 呼叫上觸發的 CloudWatch Events 規則 CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-CloudTrail-Rule.html) (Amazon CloudWatch 文件）
+ [在 AWS Glue 中設定加密](https://docs.aws.amazon.com/glue/latest/dg/set-up-encryption.html) (AWS Glue 文件）