

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

# 通过 AWS Systems Manager 自动添加或更新 Windows 注册表项
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager"></a>

*Appasaheb Bagali，Amazon Web Services*

## Summary
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-summary"></a>

AWS Systems Manager 是一款适用于亚马逊弹性计算云 (亚马逊 EC2) 实例的远程管理工具。Systems Manager 可让您查看和控制您在Amazon Web Services 上的基础设施。此多功能工具可以用于修复被安全漏洞扫描报告识别为漏洞的 Windows 注册表更改。 

此模式涵盖了通过自动更改注册表来保护运行 Windows 操作系统的 EC2 实例安全的步骤，这些更改是为了您的环境安全而建议的。该模式使用“运行”命令运行 Command 文档。该代码已附上，其中一部分包含在*代码*部分中。

## 先决条件和限制
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-prereqs"></a>
+ 一个活跃的 AWS 账户
+ 访问 EC2 实例和 Systems Manager 的权限

## 架构
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-architecture"></a>

**目标技术堆栈**
+ 具有两个子网和一个网络地址转换 (NAT) 网关的虚拟私有云（VPC）
+ 用于添加或者更新注册表名称和值的 Systems Manager Command 文档
+ Systems Manager 运行命令在指定 EC2 实例上运行命令文档

**目标架构**

![如何通过 AWS Systems Manager 自动添加或更新 Windows 注册表项。](http://docs.aws.amazon.com/zh_cn/prescriptive-guidance/latest/patterns/images/pattern-img/2ecf680d-9f36-4070-8a19-2af262db7fcc/images/c992bcb0-d894-4aa7-9bb3-3d60c9c79e8d.png)


 

## 工具
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-tools"></a>

**工具**
+ [IAM policy 和角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html) – AWS Identity and Access Management (IAM) 是一项 Web 服务，可帮助您安全地控制对 AWS 资源的访问。可以使用 IAM 来控制谁通过了身份验证（准许登录）并获得授权（具有相应权限）来使用资源。
+ [Amazon Simple Storage Service](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) – Amazon Simple Storage Service (Amazon S3) 是一项面向互联网的存储服务。该服务旨在降低开发人员进行网络规模级计算的难度。在此模式中，S3 存储桶用于存储 Systems Manager 日志。
+ [AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/what-is-systems-manager.html) – AWS Systems Manager 是一项 Amazon Web Services，可用于查看和控制 AWS 上的基础设施。Systems Manager 通过扫描*托管实例*并报告其检测到的任何策略违规行为（或采取纠正措施）来帮助您维护安全性和合规性。
+ [AWS Systems Manager Command 文档](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html) – 通过 Run Command 使用的 AWS Systems Manager Command 文档。大多数命令文档在所有 Systems Manager 所支持的 Linux 和 Windows Server 操作系统上受支持。
+ [AWS Systems Manager Run Command](https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html) – AWS Systems Manager Run Command 您提供了一种远程安全地管理托管实例配置的方法。利用 Run Command，您可以自动完成常用管理任务以及大规模执行一次性配置更改。

**代码**

您可以使用以下示例代码来添加或更新 Microsoft Windows 注册表名称 `Version`、注册表路径 `HKCU:\Software\ScriptingGuys\Scripts` 和值 `2`。

```
#Windows registry path which needs to add/update
$registryPath ='HKCU:\\Software\\ScriptingGuys\\Scripts'
#Windows registry Name  which needs to add/update
$Name = 'Version'
#Windows registry value  which needs to add/update
$value = 2
# Test-Path cmdlet to see if the registry key exists. 
IF(!(Test-Path $registryPath))
        {
           New-Item -Path $registryPath -Force | Out-Null
           New-ItemProperty -Path $registryPath -Name $name -Value     $value ` -PropertyType DWORD -                 Force | Out-        Null 
        } ELSE {
                      New-ItemProperty -Path $registryPath -Name $name -Value $value ` -PropertyType            DWORD        -Force | Out-Null
            }
echo 'Registry Path:'$registryPath
 echo 'Registry Name:'$registryPath
 echo 'Registry Value:'(Get-ItemProperty -Path $registryPath -Name $Name).version
```

随函附上完整的 Systems Manager 命令文档 JavaScript 对象表示法 (JSON) 代码示例。 

## 操作说明
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-epics"></a>

### 设置 VPC
<a name="set-up-a-vpc"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 VPC。 | 在 AWS 管理控制台，创建具有公有和私有子网以及一个 NAT 网关的 VPC。有关更多信息，请参阅 [AWS 文档](https://docs.aws.amazon.com/batch/latest/userguide/create-public-private-vpc.html)。 | 云管理员 | 
| 创建安全组。 | 确保每个安全组都允许远程桌面协议 (RDP) 从源 IP 地址访问。 | 云管理员 | 

### 创建 IAM policy 和 IAM 角色
<a name="create-an-iam-policy-and-an-iam-role"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建一个 IAM 策略。 | 创建一个 IAM 策略，提供对 Amazon S3、Amazon 和 System EC2 s Manager 的访问权限。 | 云管理员 | 
| 创建 IAM 角色。 | 创建一个 IAM 角色，并附加允许访问 Amazon S3、Amazon 和 Systems Manager 的 IA EC2 M 策略。 | 云管理员 | 

### 运行自动化
<a name="run-the-automation"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建 Systems Manager 命令文档。 | 创建 Systems Manager Command 文档，用于部署要添加或更新的 Microsoft Windows 注册表更改。 | 云管理员 | 
| 运行 Systems Manager 运行命令。 | 运行 Systems Manager Run Command，选择 Command 文档和 Systems Manager 目标实例。这会将所选 Command 文档中的 Microsoft Windows 注册表更改推送至目标实例。 | 云管理员 | 

## 相关资源
<a name="automate-adding-or-updating-windows-registry-entries-using-aws-systems-manager-resources"></a>
+ [AWS Systems Manager](https://aws.amazon.com/systems-manager/)
+ [AWS Systems Manager 文档](https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-ssm-docs.html)
+ [AWS Systems Manager 运行命令](https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html)

## 附件
<a name="attachments-2ecf680d-9f36-4070-8a19-2af262db7fcc"></a>

要访问与此文档相关联的其他内容，请解压以下文件：[attachment.zip](samples/p-attach/2ecf680d-9f36-4070-8a19-2af262db7fcc/attachments/attachment.zip)