

• AWS Systems Manager CloudWatch 控制面板在 2026 年 4 月 30 日之后将不再可用。客户可以像现在一样继续使用 Amazon CloudWatch 控制台来查看、创建和管理其 Amazon CloudWatch 控制面板。有关更多信息，请参阅 [Amazon CloudWatch 控制面板文档](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Dashboards.html)。

# 设置 Systems Manager Inventory
<a name="systems-manager-inventory-setting-up"></a>

在您使用 AWS Systems Manager Inventory 收集有关托管式节点上运行的应用程序、服务、AWS 组件等对象的元数据之前，我们建议您配置资源数据同步，以将清单数据的存储集中在单个 Amazon Simple Storage Service (Amazon S3) 存储桶中。我们还建议您配置清单事件的 Amazon EventBridge 监控。这些过程将使查看和管理清单数据和收集变得更加轻松。

**Topics**
+ [为 Inventory 创建资源数据同步](inventory-create-resource-data-sync.md)
+ [使用 EventBridge 监控 Inventory 事件](systems-manager-inventory-setting-up-eventbridge.md)

# 为 Inventory 创建资源数据同步
<a name="inventory-create-resource-data-sync"></a>

本主题介绍如何为 AWS Systems Manager Inventory 设置和配置资源数据同步。有关 Systems Manager Explorer 的资源数据同步的信息，请参阅 [设置 Systems Manager Explorer 以显示来自多个账户和区域的数据](Explorer-resource-data-sync.md)。

## 关于资源数据同步
<a name="systems-manager-inventory-datasync-about"></a>

您可以使用 Systems Manager 资源数据同步，将从所有托管式节点收集到的清单数据发送到单个 Amazon Simple Storage Service（Amazon S3）存储桶。在收集新的清单数据时，资源数据同步自动更新集中式数据。在所有清单数据存储在目标 Amazon S3 存储桶中后，可以使用 Amazon Athena 和 Amazon Quick 等服务查询和分析聚合数据。

例如，假设您将清单配置为收集有关操作系统（OS）和 150 个托管式节点机群上运行的应用程序的数据。其中某些节点位于本地数据中心内，而某些则在跨多个 AWS 区域 的 Amazon Elastic Compute Cloud（Amazon EC2）中运行。如果您*没有*配置资源数据同步，则需要手动收集为每个托管式节点收集的清单数据，或者必须创建脚本以收集该信息。然后您需要将数据传输到应用程序中，以便运行查询和分析数据。

通过使用资源数据同步，您可以执行一次性操作以同步所有托管式节点中的所有清单数据。在成功创建同步后，Systems Manager 会创建所有清单数据的基准，并将其保存在目标 Amazon S3 存储桶中。在收集新的清单数据时，Systems Manager 将自动更新 Amazon S3 存储桶中的数据。然后就可以快速且经济高效地将数据移植到 Amazon Athena 和 Amazon Quick。

图 1 显示了资源数据同步如何将来自[混合和多云](operating-systems-and-machine-types.md#supported-machine-types)环境中的 Amazon EC2 和其他计算机类型的清单数据聚合到目标 Amazon S3 存储桶。该图还显示了如何为多个 AWS 账户 和 AWS 区域 执行资源数据同步。

**图 1：为多个 AWS 账户 和 AWS 区域 执行资源数据同步**

![\[Systems Manager 资源数据同步架构\]](http://docs.aws.amazon.com/zh_cn/systems-manager/latest/userguide/images/inventory-resource-data-sync-updated.png)


如果删除一个托管式节点，则资源数据同步会保留已删除节点的清单文件。但是，对于正在运行的节点，在创建新文件并将它们写入 Amazon S3 存储桶时，资源数据同步会自动覆盖旧清单文件。如果要随着时间推移跟踪清单变化，您可以使用 AWS Config 服务跟踪 `SSM:ManagedInstanceInventory` 资源类型。有关更多信息，请参见 [AWS Config 入门](https://docs.aws.amazon.com/config/latest/developerguide/getting-started.html)。

可以按照本节中的过程，使用 Amazon S3 和 AWS Systems Manager 控制台为 Inventory 创建资源数据同步。您也可以使用 AWS CloudFormation 创建或删除资源数据同步。要使用 CloudFormation，请将 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-resourcedatasync.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ssm-resourcedatasync.html) 资源添加到您的 CloudFormation 模板。有关信息，请参阅以下文档资源：
+ [适用于 AWS Systems Manager 中的资源数据同步的 AWS CloudFormation 资源](https://aws.amazon.com/blogs/mt/aws-cloudformation-resource-for-resource-data-sync-in-aws-systems-manager/)（博客）
+ *《AWS CloudFormation 用户指南》*中的[使用 AWS CloudFormation 模板](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-guide.html)

**注意**  
可以使用 AWS Key Management Service (AWS KMS) 加密 Amazon S3 存储桶中的清单数据。有关如何使用 AWS Command Line Interface（AWS CLI）创建加密同步以及如何使用 Amazon Athena 和 Amazon Quick 中的集中式数据的示例，请参阅[演练：使用资源数据同步聚合清单数据](inventory-resource-data-sync.md)。

## 开始前的准备工作
<a name="datasync-before-you-begin"></a>

在创建资源数据同步之前，请使用以下过程创建中央 Amazon S3 存储桶，以存储聚合清单数据。该过程介绍如何分配存储桶策略，以便 Systems Manager 能将来自多个账户的清单数据写入存储桶。如果您已有一个要用于聚合清单数据以进行资源数据同步的 Amazon S3 存储桶，则必须在以下过程中将该存储桶配置为使用该策略。

**注意**  
如果指定的 Amazon S3 存储桶被配置为使用对象锁定，则 Systems Manager Inventory 无法将数据添加到该存储桶。请验证并确保您为资源数据同步创建或选择的 Amazon S3 存储桶未被配置为使用 Amazon S3 对象锁定。有关更多信息，请参阅*《Amazon Simple Storage Service 用户指南》*中的 [Amazon S3 对象锁定的工作原理](https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lock-overview.html)。

**为资源数据同步创建和配置 Amazon S3 存储桶**

1. 通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 创建用来存储聚合清单数据的存储桶。有关更多信息，请参阅[《Amazon Simple Storage Service 用户指南》](https://docs.aws.amazon.com/AmazonS3/latest/userguide/CreatingABucket.html)中的*创建存储桶*。请记下存储桶名称和创建此存储桶的 AWS 区域。

1. 选择**权限**选项卡，然后选择**存储桶策略**。

1. 将下面的存储桶策略复制并粘贴到策略编辑器中。将 *amzn-s3-demo-bucket* 替换为您创建的 S3 存储桶的名称。将 *account\$1ID\$1number* 替换为有效的 AWS 账户 ID 号码。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "SSMBucketPermissionsCheck",
               "Effect": "Allow",
               "Principal": {
                   "Service": "ssm.amazonaws.com"
               },
               "Action": "s3:GetBucketAcl",
               "Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
           },
           {
               "Sid": " SSMBucketDelivery",
               "Effect": "Allow",
               "Principal": {
                   "Service": "ssm.amazonaws.com"
               },
               "Action": "s3:PutObject",
               "Resource": [
                   "arn:aws:s3:::amzn-s3-demo-bucket/*/accountid=111122223333/*",
                   "arn:aws:s3:::amzn-s3-demo-bucket/*/accountid=444455556666/*",
                   "arn:aws:s3:::amzn-s3-demo-bucket/*/accountid=123456789012/*",
                   "arn:aws:s3:::amzn-s3-demo-bucket/*/accountid=777788889999/*"
               ],
               "Condition": {
                   "StringEquals": {
                       "s3:x-amz-acl": "bucket-owner-full-control",
                       "aws:SourceAccount": "111122223333"
                   },
                   "ArnLike": {
                       "aws:SourceArn": "arn:aws:ssm:*:111122223333:resource-data-sync/*"
                   }
               }
           }
       ]
   }
   ```

------

1. 保存更改。

## 为 Inventory 创建资源数据同步
<a name="datasync-create"></a>

按照以下过程，使用 Systems Manager 控制台为 Systems Manager Inventory 创建资源数据同步。有关如何使用 AWS CLI 创建资源数据同步的信息，请参阅 [使用 AWS CLI 配置清单数据收集](inventory-collection-cli.md)。

**创建资源数据同步**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Fleet Manager**。

1. 在**账户管理**菜单中，选择**资源数据同步**。

1. 选择**创建资源数据同步**。

1. 在**同步名称**字段中，输入同步配置的名称。

1. 在**存储桶名称**字段中，输入您使用**为资源数据同步创建和配置 Amazon S3 存储桶**过程创建的 Amazon S3 存储桶的名称。

1. （可选）在**存储桶前缀**字段中，输入 Amazon S3 存储桶前缀（子目录）的名称。

1. 在**存储桶区域**字段中，如果您创建的 Amazon S3 存储桶位于当前的 AWS 区域 中，请选择**此区域**。如果存储桶位于其他 AWS 区域 中，则请选择**其他区域**，然后输入该区域的名称。
**注意**  
如果同步和目标 Amazon S3 存储桶位于不同区域中，您可能需要支付数据传输费用。有关更多信息，请参阅 [Amazon S3 定价](https://aws.amazon.com/s3/pricing/)。

1. （可选）在 **KMS 密钥 ARN** 字段中，键入或粘贴 KMS 密钥 ARN，以加密 Amazon S3 中的清单数据。

1. 选择**创建**。

要同步来自多个 AWS 区域的清单数据，您必须在*每个*区域中创建一个资源数据同步。在要收集清单数据并将其发送到中央 Amazon S3 存储桶的每个 AWS 区域 中重复此过程。当您在每个区域中创建同步时，请在**存储桶名称**字段中指定中央 Amazon S3 存储桶。然后，使用**存储桶区域**选项选择要在其中创建中央 Amazon S3 存储桶的区域，如下面的屏幕截图中所示。下次关联运行以收集清单数据时，Systems Manager 会将数据存储在中央 Amazon S3 存储桶中。

![\[来自多个 AWS 区域的 Systems Manager 资源数据同步\]](http://docs.aws.amazon.com/zh_cn/systems-manager/latest/userguide/images/inventory-rds-multiple-regions.png)


## 为 AWS Organizations 中定义的多个账户创建清单资源数据同步
<a name="systems-manager-inventory-resource-data-sync-AWS-Organizations"></a>

您可以将来自 AWS Organizations 中定义的 AWS 账户的清单数据同步到中央 Amazon S3 存储桶。完成以下过程后，清单数据将同步到中央存储桶中的*各个* Amazon S3 密钥前缀。每个键前缀均代表一个不同的 AWS 账户 ID。

**开始前的准备工作**  
在开始之前，请验证并确保您已在 AWS Organizations 中设置和配置了多个 AWS 账户。有关更多信息，请参阅《AWS Organizations 用户指南》中的** [https://docs.aws.amazon.com/organizations/latest/userguide/rgs_getting-started.html](https://docs.aws.amazon.com/organizations/latest/userguide/rgs_getting-started.html)。

另外，请注意，您必须为 AWS Organizations 中定义的每个 AWS 区域 和 AWS 账户 创建基于组织的资源数据同步。

### 创建中央 Amazon S3 存储桶
<a name="datasync-s3-bucket"></a>

可以使用以下过程创建中央 Amazon S3 存储桶，以存储聚合清单数据。该过程介绍如何分配存储桶策略，以便 Systems Manager 能将来自您的 AWS Organizations 账户 ID 的清单数据写入存储桶。如果您已有一个要用于聚合清单数据以进行资源数据同步的 Amazon S3 存储桶，则必须在以下过程中将该存储桶配置为使用该策略。

**为 AWS Organizations 中定义的多个账户的资源数据同步创建和配置 Amazon S3 存储桶**

1. 通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 创建用来存储聚合清单数据的存储桶。有关更多信息，请参阅[《Amazon Simple Storage Service 用户指南》](https://docs.aws.amazon.com/AmazonS3/latest/userguide/CreatingABucket.html)中的*创建存储桶*。请记下存储桶名称和创建此存储桶的 AWS 区域。

1. 选择**权限**选项卡，然后选择**存储桶策略**。

1. 将下面的存储桶策略复制并粘贴到策略编辑器中。将 *amzn-s3-demo-bucket* 和 *organization-id* 分别替换为您创建的 Amazon S3 存储桶的名称和有效的 AWS Organizations 账户 ID。

   或者，将 *bucket-prefix* 替换为 Amazon S3 前缀（子目录）的名称。如果您未创建前缀，则从以下策略的 ARN 中删除 *bucket-prefix/*。

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Sid": "SSMBucketPermissionsCheck",
         "Effect": "Allow",
         "Principal": {
           "Service": "ssm.amazonaws.com"
         },
         "Action": "s3:GetBucketAcl",
         "Resource": "arn:aws:s3:::amzn-s3-demo-bucket"
       },
       {
         "Sid": " SSMBucketDelivery",
         "Effect": "Allow",
         "Principal": {
           "Service": "ssm.amazonaws.com"
         },
         "Action": "s3:PutObject",
         "Resource": [
           "arn:aws:s3:::amzn-s3-demo-bucket/bucket-prefix/*/accountid=*/*"
         ],
         "Condition": {
           "StringEquals": {
             "s3:x-amz-acl": "bucket-owner-full-control",
             "aws:SourceOrgID": "organization-id"
                     }
         }
       },
       {
         "Sid": " SSMBucketDeliveryTagging",
         "Effect": "Allow",
         "Principal": {
           "Service": "ssm.amazonaws.com"
         },
         "Action": "s3:PutObjectTagging",
         "Resource": [
           "arn:aws:s3:::amzn-s3-demo-bucket/bucket-prefix/*/accountid=*/*"
         ]
       }
     ]
   }
   ```

------

### 为 AWS Organizations 中定义的账户创建清单资源数据同步
<a name="systems-manager-inventory-resource-data-sync-AWS-Organizations-create"></a>

以下过程介绍如何使用 AWS CLI 为 AWS Organizations 中定义的账户创建资源数据同步。您必须使用 AWS CLI 执行此任务。您还必须为 AWS Organizations 中定义的每个 AWS 区域 和 AWS 账户 执行此过程。

**为 AWS Organizations 中定义的账户创建资源数据同步 (AWS CLI)**

1. 安装并配置 AWS Command Line Interface（AWS CLI）（如果尚未执行该操作）。

   有关更多信息，请参阅[安装或更新 AWS CLI 的最新版本](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)。

1. 运行以下命令，验证并确保您没有任何其他*基于 AWS Organizations* 的资源数据同步。可以有多个标准同步，包括多个标准同步和一个基于组织的同步。但是只能有一个基于组织的资源数据同步。

   ```
   aws ssm list-resource-data-sync
   ```

   如果该命令返回了另一个基于组织的资源数据同步，则您必须将其删除，或选择不创建新资源数据同步。

1. 运行以下命令，为 AWS Organizations 中定义的账户创建资源数据同步。对于 amzn-s3-demo-bucket，请指定您在本主题的前面创建的 Amazon S3 存储桶的名称。如果您为存储桶创建了前缀（子目录），则为 *prefix-name* 指定此信息。

   ```
   aws ssm create-resource-data-sync --sync-name name --s3-destination "BucketName=amzn-s3-demo-bucket,Prefix=prefix-name,SyncFormat=JsonSerDe,Region=AWS 区域, for example us-east-2,DestinationDataSharing={DestinationDataSharingType=Organization}"
   ```

1. 为您希望在其中将数据同步到中央 Amazon S3 存储桶的每个 AWS 区域 和 AWS 账户 重复步骤 2 和步骤 3。

### 管理资源数据同步
<a name="managing-resource-data-syncs"></a>

每个 AWS 账户 在每个 AWS 区域 可以有 5 个资源数据同步。您可以使用 AWS Systems Manager Fleet Manager 控制台来管理您的资源数据同步。

**查看资源数据同步**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Fleet Manager**。

1. 在**账户管理**下拉菜单中，选择**资源数据同步**。

1. 从表中选择资源数据同步，然后选择**查看详细信息**以查看有关资源数据同步的信息。

**删除资源数据同步**

1. 访问 [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/)，打开 AWS Systems Manager 控制台。

1. 在导航窗格中，请选择 **Fleet Manager**。

1. 在**账户管理**下拉菜单中，选择**资源数据同步**。

1. 从表中选择资源数据同步，然后选择**删除**。

# 使用 EventBridge 监控 Inventory 事件
<a name="systems-manager-inventory-setting-up-eventbridge"></a>

您可以在 Amazon EventBridge 中配置规则来创建事件，以响应 AWS Systems Manager Inventory 资源状态更改。EventBridge 支持针对以下 Inventory 状态更改的事件。将尽最大努力发送所有事件。

**Custom inventory type deleted for a specific instance**（针对特定实例删除的自定义清单类型）：如果配置了用于监控此事件的规则，EventBridge 将在删除特定托管式节点上的自定义清单类型时创建一个事件。EventBridge 将针对每个自定义清单类型的每个节点发送一个事件。以下是一个示例事件模式。

```
{
    "timestampMillis": 1610042981103,
    "source": "SSM",
    "account": "123456789012",
    "type": "INVENTORY_RESOURCE_STATE_CHANGE",
    "startTime": "Jan 7, 2021 6:09:41 PM",
    "resources": [
        {
            "arn": "arn:aws:ssm:us-east-1:123456789012:managed-instance/i-12345678"
        }
    ],
    "body": {
        "action-status": "succeeded",
        "action": "delete",
        "resource-type": "managed-instance",
        "resource-id": "i-12345678",
        "action-reason": "",
        "type-name": "Custom:MyCustomInventoryType"
    }
}
```

**Custom inventory type deleted event for all instances**（所有实例的自定义清单类型删除事件）：如果配置了用于监控此事件的规则，EventBridge 将在删除适用于所有托管式节点的自定义清单类型时创建一个事件。以下是一个示例事件模式。

```
{
    "timestampMillis": 1610042904712,
    "source": "SSM",
    "account": "123456789012",
    "type": "INVENTORY_RESOURCE_STATE_CHANGE",
    "startTime": "Jan 7, 2021 6:08:24 PM",
    "resources": [
        
    ],
    "body": {
        "action-status": "succeeded",
        "action": "delete-summary",
        "resource-type": "managed-instance",
        "resource-id": "",
        "action-reason": "The delete for type name Custom:SomeCustomInventoryType was completed. The deletion summary is: {\"totalCount\":1,\"remainingCount\":0,\"summaryItems\":[{\"version\":\"1.1\",\"count\":1,\"remainingCount\":0}]}",
        "type-name": "Custom:MyCustomInventoryType"
    }
}
```

**[PutInventory](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_PutInventory.html) call with old schema version event (使用旧架构版本事件进行 PutInventory 调用)**：如果配置了用于监控此事件的规则，EventBridge 将在使用低于当前架构的架构版本进行 PutInventory 调用时创建一个事件。此事件适用于所有清单类型。以下是一个示例事件模式。

```
{
    "timestampMillis": 1610042629548,
    "source": "SSM",
    "account": "123456789012",
    "type": "INVENTORY_RESOURCE_STATE_CHANGE",
    "startTime": "Jan 7, 2021 6:03:49 PM",
    "resources": [
        {
            "arn": "arn:aws:ssm:us-east-1:123456789012:managed-instance/i-12345678"
        }
    ],
    "body": {
        "action-status": "failed",
        "action": "put",
        "resource-type": "managed-instance",
        "resource-id": "i-01f017c1b2efbe2bc",
        "action-reason": "The inventory item with type name Custom:MyCustomInventoryType was sent with a disabled schema verison 1.0. You must send a version greater than 1.0",
        "type-name": "Custom:MyCustomInventoryType"
    }
}
```

有关如何配置 EventBridge 以监控这些事件的信息，请参阅 [为 Systems Manager 事件配置 EventBridge](monitoring-systems-manager-events.md)。