

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 AWS CloudFormation 模板在 AWS Glue 中自动执行加密
<a name="automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template"></a>

*Diogo Guedes，Amazon Web Services*

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

此模式向您展示如何使用 AWS CloudFormation 模板在 AWS Glue 中设置和自动执行加密。该模板创建强制加密所需所有配置和资源。这些资源包括初始配置、由亚马逊 EventBridge 规则创建的预防性控制和 AWS Lambda 函数。

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

**先决条件**
+ 一个活跃的 AWS 账户
+ 部署 CloudFormation 模板及其资源的权限

**限制**

这种安全控制为区域性的。您必须在每个要对 AWS Glue 中设置加密强制性的AWS 区域 部署安全控件。

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

**目标技术堆栈**
+ 亚马逊 CloudWatch 日志（来自 AWS Lambda）
+ 亚马逊 EventBridge 规则
+ AWS CloudFormation 堆栈
+ AWS CloudTrail
+ AWS Identity and Access Management (IAM) 托管角色和策略
+ AWS Key Management Service (AWS KMS)
+ AWS KMS 别名
+ AWS Lambda 函数
+ AWS Systems Manager Parameter Store

**目标架构**

下图显示了如何在 AWS Glue 中自动执行加密。

![\[该图显示了如何使用 CloudFormation 模板在 AWS Glue 中自动执行加密。\]](http://docs.aws.amazon.com/zh_cn/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 日志调用 Lambda 函数进行评估和记录。对于不合规性检测，通过 AWS KMS 密钥的 Amazon 资源名称（ARN）恢复 Parameter Store。该服务已修复为启用加密的合规状态。

**自动化和扩展**

如果您使用的是 [AWS Org](https://aws.amazon.com/organizations/) anizations，则可以使用 [AWS](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/what-is-cfnstacksets.html) 将此模板部署 CloudFormation StackSets到要在 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 可帮助您对 AWS](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-user-guide.html) 账户进行运营和风险审计、监管和合规。
+ [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) 可帮助您管理在 Amazon Web Services Cloud 中运行的应用程序和基础设施。它简化了应用程序和资源管理，缩短了检测和解决操作问题的时间，并帮助您大规模安全地管理 AWS 资源。

**代码**

此模式的代码可在 GitHub [aws-custom-guardrail-event驱动的存储库中](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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 部署 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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 检查 AWS KMS 密钥配置。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-encryption-enforcement-in-aws-glue-using-an-aws-cloudformation-template.html) | 云架构师 | 

### 测试加密强制执行
<a name="test-the-encryption-enforcement"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在中标识加密设置 CloudFormation。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/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_cn/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 创建在 AWS API 调用时触发 CloudWatch 的事件规则 CloudTrail](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-CloudTrail-Rule.html)（亚马逊 CloudWatch 文档）
+ [在 AWS Glue 中设置加密](https://docs.aws.amazon.com/glue/latest/dg/set-up-encryption.html)（AWS Glue 文档）