

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

# 自动清点多个账户和地区的 AWS 资源
<a name="automate-aws-resource-inventory"></a>

*Matej Macek，Amazon Web Services*

## Summary
<a name="automate-aws-resource-inventory-summary"></a>

这种模式概述了一种自动化方法，用于维护多个帐户的全面 AWS 资源清单，以及 AWS 区域. 它旨在帮助基础设施和安全工程师改善其资源管理实践。它用于跟踪资源变化，Amazon Athena 用于查询，Amazon Quick Sight 用于跟踪 AWS Config 交互式仪表板。您可以通过部署 AWS CloudFormation 堆栈来实现此解决方案。

此解决方案与[使用 Amazon Athena 和 Amazon Qu AWS ick Sight 可视化 AWS Config 数据（博](https://aws.amazon.com/blogs/mt/visualizing-aws-config-data-using-amazon-athena-and-amazon-quicksight/)客文章）中介绍的解决方案类似。此模式扩展了该解决方案，以满足以下常见要求并提供以下主要优势：
+ **聚焦合规性** – 这种方法可以帮助您满足监管要求，例如 [PCI DSS](https://www.pcisecuritystandards.org/)、[NIST SP 800-53](https://csrc.nist.gov/pubs/sp/800/53/r5/upd1/final)、[ISO/IEC 27001](https://www.iso.org/standard/27001)、[HIPAA](https://www.hhs.gov/programs/hipaa/index.html)、[GDPR](https://gdpr.eu/) 以及其他要求准确资产库存的监管要求。
+ **自定义框架** — 它为为各种 AWS 资源创建 Quick Sight 仪表板提供了基础，因此您可以根据自己的特定要求自定义解决方案。
+ **以用户为导向的增强功能** – 这种方法结合了来自实际使用案例的反馈，并满足了对更全面解决方案的要求。

在动态、多账户或多区域环境中，基础设施、安全和财务团队经常面临可见性和协作方面的挑战。此解决方案旨在解决这些难题，并显著减少创建和维护资源清单所需的时间和精力。结果获得资源的集中视图，它可帮助您改进资源分配决策，识别和降低风险，优化成本，并改善整体可见性和协作。这种方法弥合了概念性解决方案与实际实施需求之间的差距，以实现安全、合规和运营目的。

## 先决条件和限制
<a name="automate-aws-resource-inventory-prereqs"></a>

**先决条件**
+ 以下活跃 AWS 账户：
  + *管理账户* - 用于在整个组织内计费、创建账户和控制访问权限的集中账户
  + *审计账户* – 用于安全监控、合规性检查和偏差通知的集中式中心
  + *日志存档账户* – 用于存储和分析所收集数据的集中账户
+ 在审计账户中，一种 AWS Config [聚合器](https://docs.aws.amazon.com/config/latest/developerguide/aggregate-data.html)，用于收集和汇总来自目标账户和地区的配置数据
+ 在日志存档账户中，设置以下内容：
  + 亚马逊简单存储服务 (Amazon S3) [S](https://docs.aws.amazon.com/AmazonS3/latest/userguide/create-bucket-overview.html) ervice 存储桶，用于存储来自聚合器的数据 AWS Config 
  + Amazon Quick [订阅](https://docs.aws.amazon.com/quicksight/latest/user/signing-up.html)
  + Quick Sight 和亚马逊 Athena 之间的[授权连接](https://docs.aws.amazon.com/quicksight/latest/user/athena.html)
  + 通过 Athena 查询来访问 Amazon S3 存储桶的[权限](https://docs.aws.amazon.com/athena/latest/ug/s3-permissions.html)
+ AWS Command Line Interface (AWS CLI)，[已安装](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)并[配置](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
+ 部署预置以下资源的 CloudFormation 堆栈的权限：
  + 一个 AWS Lambda 函数
  + Amazon S3 通知配置
  + Athena 数据库、表和视图
  + Quick Sight 数据集和数据源
+ 在中运行自动化的权限 AWS Systems Manager
+ Quick 访问权限

**限制**
+ 解决方案依赖于 AWS Config。 AWS Config 通常会在检测到更改后立即或按您指定的频率记录对资源的配置更改。但是，这需要尽最大努力，有时可能需要更长的时间。
+ 此解决方案仅跟踪[AWS Config 支持的资源类型](https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html)。
+ 该解决方案不跟踪其他云提供商或本地环境中的资源库存。
+ 有些 AWS 服务 并非全部可用 AWS 区域。有关区域可用性，请参阅 AWS 文档中的[服务终端节点和配额](https://docs.aws.amazon.com/general/latest/gr/aws-service-information.html)页面，然后选择该服务的链接。

## 架构
<a name="automate-aws-resource-inventory-architecture"></a>

下图显示了收集、组织、分析和可视化组织中多个账户的配置和合规性数据的简化流程。 AWS 

![\[收集并可视化整个组织中的配置和合规性数据。\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/67a9667a-da19-4dcb-a2fe-62bc94a0541b/images/c9245de1-ac85-4a9e-a0c0-dbcc27a8bb5d.png)


下图显示了如下工作流：

1.  AWS Config 聚合器定期收集有关目标账户和区域中资源的配置和合规性数据，然后将这些数据传输到日志存档账户中的 Amazon S3 存储桶。

1. 向 Amazon S3 存储桶添加新 AWS Config 数据会调用一个 AWS Lambda 函数。

1. Lambda 函数通过配置与每个快照文件的区域和日期相对应的键-值来对数据进行分区。这有助于 AWS Glue 有效地查询和处理配置和合规性数据。

1. Amazon Athena 使用架构 AWS Glue [对](https://docs.aws.amazon.com/glue/latest/dg/schema-registry.html)存储在 Amazon S3 存储桶中的数据运行 SQL 查询。它利用中的架构元数据 AWS Glue 来理解数据的结构。

1. Athena 中的[视图](https://docs.aws.amazon.com/athena/latest/ug/views.html)定义和提取目标数据集。

1. Quick Sight 中的@@ [仪表板](https://docs.aws.amazon.com/quicksight/latest/user/using-dashboards.html)可帮助您可视化和分析数据集。

## 工具
<a name="automate-aws-resource-inventory-tools"></a>

**AWS 服务**
+ [Amazon Athena](https://docs.aws.amazon.com/athena/latest/ug/what-is.html) 是一种交互式查询服务，它可帮助您通过使用标准 SQL 直接在 Amazon S3 中分析数据。
+ [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)帮助您设置 AWS 资源，快速一致地配置资源，并在和的整个 AWS 账户 生命周期中对其进行管理 AWS 区域。
+ [AWS Config](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)提供了您的资源 AWS 账户 及其配置方式的详细视图。它可以帮助您确定资源之间的相互关系，以及它们的配置如何随时间变化。 AWS Config [聚合器](https://docs.aws.amazon.com/config/latest/developerguide/aggregate-data.html)从多个 AWS 账户 区域收集 AWS Config 配置和合规性数据。
+ [AWS Glue](https://docs.aws.amazon.com/glue/latest/dg/what-is-glue.html) 是一项完全托管式提取、转换、加载（ETL）服务。它可以帮助您在数据存储和数据流之间对数据进行可靠地分类、清理、扩充和移动。此模式使用 AWS Glue [数据目录](https://docs.aws.amazon.com/glue/latest/dg/components-overview.html#data-catalog-intro)和[架构注册表](https://docs.aws.amazon.com/glue/latest/dg/schema-registry.html)。
+ [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html) 是一项计算服务，可帮助您运行代码，无需预调配或管理服务器。它只在需要时运行您的代码，并自动进行扩展，因此您只需为使用的计算时间付费。
+ [AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html)是一项账户管理服务，可帮助您将多个账户整合 AWS 账户 到一个由您创建和集中管理的组织中。
+ [Amazon Quick Sight](https://docs.aws.amazon.com/quicksuite/latest/userguide/quick-bi.html) 是一项商业智能 (BI) 服务，可通过交互式可视化、仪表板和报告帮助您将原始数据转化为有意义的见解。Quick Sight 是 Amazon Quick 的核心组件。
+ [Amazon Simple Storage Service（Amazon S3）](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html)是一项基于云的对象存储服务，可帮助您存储、保护和检索任意数量的数据。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) 可帮助您管理在 AWS 云中运行的应用程序和基础设施。它简化了应用程序和资源管理，缩短了检测和解决操作问题的时间，并帮助您大规模安全地管理 AWS 资源。[AWS Systems Manager 自动化](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html)简化了许多人的常见维护、部署和补救任务 AWS 服务。

**代码存储库**

此模式的 AWS CloudFormation 模板可在可[AWS Config 视化](https://github.com/aws-samples/aws-management-and-governance-samples/blob/master/AWSConfig/AWS-Config-Visualization/README.md) GitHub 存储库中找到。此 CloudFormation 模板部署了 AWS Systems Manager 自动运行手册，该操作手册设置 AWS Config 为与 Amazon Athena 配合使用。此自动化 AWS Glue 可以准备连接指定的 Amazon S3 存储桶，在 Amazon Athena 中创建视图，并配置 Quick Sight 以实现控制面板可视化。

## 最佳实践
<a name="automate-aws-resource-inventory-best-practices"></a>
+ 我们建议您遵循[设置和管理安全的多账户 AWS 环境中的最佳实践，而不是 AWS 规范 AWS Control Tower性](https://docs.aws.amazon.com/prescriptive-guidance/latest/migration-aws-environment/welcome.html)指导。
+ 我们建议您创建一个 AWS Config 聚合器来收集整个 AWS 组织的配置和合规性数据。有关更多信息，请参阅文档中的[多账户多区域数据聚合](https://docs.aws.amazon.com/config/latest/developerguide/aggregate-data.html)。 AWS Config 
+ [在部署此解决方案之前，我们建议您查看 A [mazon S3 [AWS Config](https://aws.amazon.com/config/pricing/)](https://aws.amazon.com/s3/pricing/)、[Athena](https://aws.amazon.com/athena/pricing/) 和 Quick 的当前定价信息。](https://aws.amazon.com/quicksight/pricing/)

## 操作说明
<a name="automate-aws-resource-inventory-epics"></a>

### 部署堆 CloudFormation 栈
<a name="deploy-the-cfnshort-stack"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 下载 CloudFormation 模板。 | 下载 Config-Visualizat [ion QuickSight-SSM-Automation.yaml 模板](https://github.com/aws-samples/aws-management-and-governance-samples/blob/master/AWSConfig/AWS-Config-Visualization/cft/Config-QuickSight-Visualization-SSM-Automation.yaml) CloudFormation 。 | AWS 管理员、云管理员、 DevOps 工程师 | 
| 修改 CloudFormation 模板。 | 只有当你正在使用[AWS Control Tower](https://aws.amazon.com/controltower/)并 AWS Config 由其管理时，才能完成此步骤 AWS Control Tower。您需要修改 CloudFormation 模板。[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | DevOps 工程师，AWS 管理员 | 
| 创建堆 CloudFormation 栈。 | 按照[从 CloudFormation 控制台创建堆栈中的说明进行操作](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-create-stack.html)。注意以下几点：[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | AWS 管理员、云管理员、 DevOps 工程师 | 

### 在 Systems Manager 中运行自动化
<a name="run-the-automation-in-sys"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 找到您的快捷用户名。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | AWS 管理员、云管理员、 DevOps 工程师 | 
| 查找传输通道名称和 Amazon S3 存储桶名称。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | AWS 管理员、云管理员、 DevOps 工程师 | 
| 在 Systems Manager 中运行自动化。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | AWS 管理员、云管理员、 DevOps 工程师 | 

### 在快速视图中可视化数据
<a name="visualize-data-in-qsight"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 刷新数据。 | 要根据您的特定要求安排数据集刷新，请按照[刷新 SPICE 数据](https://docs.aws.amazon.com/quicksight/latest/user/refreshing-imported-data.html)中的说明操作。 | AWS 管理员、 DevOps 工程师、云管理员 | 
| 创建分析。 | 要在 Quick Sight 中创建可帮助您可视化资源的仪表板，请按照在 [Quick Sight 中开始分析中的](https://docs.aws.amazon.com/quicksuite/latest/userguide/creating-an-analysis.html)说明进行操作。 | 快速套件管理员 | 
| 创建控制面板。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | 快速套件管理员 | 

### （可选）清理
<a name="optional-clean-up"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 删除 Systems Manager 自动化创建的资源。 | [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/automate-aws-resource-inventory.html) | AWS 管理员、云管理员、 DevOps 工程师 | 
| 删除 CloudFormation 堆栈。 | 要删除`Config-QuickSight-Visualization-SSM-Automation`堆栈中的资源，请按照[从 CloudFormation 控制台删除堆栈中的说明进行](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-console-delete-stack.html)操作。 | AWS 管理员、云管理员、 DevOps 工程师 | 

## 问题排查
<a name="automate-aws-resource-inventory-troubleshooting"></a>


| 问题 | 解决方案 | 
| --- | --- | 
| Amazon Quick 正在尝试连接到 `us-east-1` AWS 区域，但不允许在该地区创建资源。 | 一项服务控制政策限制您在该地区订阅 Amazon Quick。在服务控制策略中，手动指定目标 AWS 区域。将 `<REGION_ID>` 替换为相应的区域标识符：<pre>https://<REGION_ID>.quicksight.aws.amazon.com/sn/start/dashboards</pre>以下是示例：<pre>https://eu-central-1.quicksight.aws.amazon.com/sn/start/dashboards</pre> | 
| 在 Amazon Athena 中，您会遇到以下消息：`Before you run your first query, you need to set up a query result location in Amazon S3.` | 确保您已准备了一个 Amazon S3 存储桶，用于存储 Amazon Athena 的查询结果。然后按照[使用 Amazon Athena 控制台指定查询结果位置](https://docs.aws.amazon.com/athena/latest/ug/query-results-specify-location-console.html)中的说明操作。 | 

## 相关资源
<a name="automate-aws-resource-inventory-resources"></a>

**AWS 文档**
+ [AWS Config 文档](https://docs.aws.amazon.com/config/latest/developerguide/WhatIsConfig.html)
+ [Amazon Quick 文档](https://docs.aws.amazon.com/quicksuite/latest/userguide/what-is.html)

**AWS 博客文章**
+ [使用自动实现 AWS Config 数据可视化 AWS Systems Manager](https://aws.amazon.com/blogs/mt/automate-aws-config-data-visualization-with-aws-systems-manager/)
+ [如何使用定期记录资源配置的变化 AWS Config](https://aws.amazon.com/blogs/mt/how-to-record-resource-configuration-changes-periodically-with-aws-config/)

**其他资源**
+ [Amazon 快速社区学习中心](https://community.amazonquicksight.com/c/learning-center/10/none)
+ [Amazon Quick 社区画廊](https://community.amazonquicksight.com/c/gallery/44)