将 EC2Rescue for Windows Server 与 Systems Manager Run Command 结合使用
Amazon Web Services Support 为您提供了 Systems Manager Run Command 文档,目的是与您启用了 Systems Manager 的实例交互来运行 EC2Rescue for Windows Server。Run Command 文档称为 AWSSupport-RunEC2RescueForWindowsTool。
此 Systems Manager Run Command 文档执行下列任务:
-
下载并验证 EC2Rescue for Windows Server。
-
导入 PowerShell 模块以使您与此工具的交互变得简单。
-
使用提供的命令和参数运行 EC2RescueCmd。
Systems Manager Run Command 文档接受三个参数:
-
命令 — EC2Rescue for Windows Server 操作。当前允许的值如下:
-
ResetAccess — 重置本地管理员密码。将会重置当前实例的本地管理员密码,并且随机生成的密码将会作为
/EC2Rescue/Password/<INSTANCE_ID>安全地存储在 Parameter Store 中。如果您选择此操作并且不提供任何参数,则密码将自动使用默认的 KMS 密钥 密钥加密。(可选)可以在参数中指定 KMS 密钥 ID,以使用您自己的密钥来加密密码。 -
CollectLogs — 使用
/collect:all操作运行 EC2Rescue for Windows Server。如果选择此操作,Parameters必须包含将日志上传到的 Amazon S3 存储桶名称。 -
FixAll — 使用
/rescue:all操作运行 EC2Rescue for Windows Server。如果您选择此操作,Parameters必须包含要抢救的块储存设备名称。
-
-
参数 — 要为指定命令传递的 PowerShell 参数。
为使 ResetAccess 操作正常工作,您的 Amazon EC2 实例需要附加以下策略,以便将加密的密码写入到 Parameter Store 中。在将此策略附加到相关 IAM 角色之后,请稍候几分钟,然后再尝试重置实例的密码。
使用默认 KMS 密钥:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssm:PutParameter" ], "Resource": [ "arn:aws:ssm:region:account_id:parameter/EC2Rescue/Passwords/<instanceid>" ] } ] }
使用自定义 KMS 密钥:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "ssm:PutParameter" ], "Resource": [ "arn:aws:ssm:region:account_id:parameter/EC2Rescue/Passwords/<instanceid>" ] }, { "Effect": "Allow", "Action": [ "kms:Encrypt" ], "Resource": [ "arn:aws:kms:region:account_id:key/<kmskeyid>" ] } ] }
以下过程描述如何在 Amazon EC2 控制台中查看此文档的 JSON。
查看 Systems Manager Run Command 文档的 JSON
-
在 https://console.aws.amazon.com/systems-manager/home
处打开 Systems Manager 控制台。 -
在导航窗格中,展开 Shared Services 并选择 Documents。
-
在搜索栏中,将拥有者设置为我或 Amazon 所拥有并将文档名称前缀设置为
AWSSupport-RunEC2RescueForWindowsTool。 -
选择
AWSSupport-RunEC2RescueForWindowsTool文档,选择 Contents,然后查看 JSON。
示例
下面是一些有关如何使用 Systems Manager Run Command 文档通过 Amazon CLI 运行 EC2Rescue for Windows Server 的示例。有关使用 Amazon CLI 发送命令的更多信息,请参阅 Amazon CLI Command Reference。
尝试修复脱机根卷上的所有已识别问题
尝试修复在附加到 Amazon EC2Windows 实例的脱机根卷上发现的所有问题:
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --comment "EC2Rescue offline volume xvdf" --parameters "Command=FixAll, Parameters='xvdf'" --output text
从当前 Amazon EC2 Windows 实例收集日志
从当前的在线 Amazon EC2 Windows 实例收集所有日志并将日志上传到 Amazon S3 存储桶:
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --comment "EC2Rescue online log collection to S3" --parameters "Command=CollectLogs, Parameters='YOURS3BUCKETNAME'" --output text
从脱机 Amazon EC2 Windows 实例卷收集日志
从附加到 Amazon EC2 Windows 实例的脱机卷收集所有日志,并使用预签名 URL 将日志上传到 Amazon S3:
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --comment "EC2Rescue offline log collection to S3" --parameters "Command=CollectLogs, Parameters=\"-Offline -BlockDeviceNamexvdf-S3PreSignedUrl 'YOURS3PRESIGNEDURL'\"" --output text
重置本地管理员密码
下面的示例显示了可用于重置本地管理员密码的方法。输出提供了一个指向 Parameter Store 的链接,在那里您可以找到随机生成的安全密码,然后您可以使用它以本地管理员身份来 RDP 到您的 Amazon EC2 Windows 实例。
使用默认的 Amazon KMS key 密钥 alias/aws/ssm 重置联机实例的本地管理员密码:
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --comment "EC2Rescue online password reset" --parameters "Command=ResetAccess" --output text
使用 KMS 密钥 重置联机实例的本地管理员密码:
aws ssm send-command --instance-ids "i-0cb2b964d3e14fd9f" --document-name "AWSSupport-RunEC2RescueForWindowsTool" --comment "EC2Rescue online password reset" --parameters "Command=ResetAccess, Parameters=a133dc3c-a2g4-4fc6-a873-6c0720104bf0" --output text
在此示例中,KMS 密钥 为 a133dc3c-a2g4-4fc6-a873-6c0720104bf0。