我使用Terraform启动了windows EC2实例。我们用了自己的AMI。在terraform中,我在创建实例时将powershell脚本附加到用户数据。在启动实例之后,我从AWS控制台验证了实例是否附带了以下用户数据。
然后,我在C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log
中签入了日志,但是没有看到powershell脚本的任何输出。下面是日志中的片段
2022/11/05 06:27:13Z: Begin user data script process.
2022/11/05 06:27:13Z: Unable to parse <persist> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:27:13Z: Sending telemetry bool: IsUserDataScheduledPerBoot
2022/11/05 06:27:13Z: Unregister the scheduled task to persist user data.
2022/11/05 06:27:15Z: Unable to parse <runAsLocalSystem> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:27:15Z: Unable to parse <script> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:27:15Z: Unable to parse <powershellArguments> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:27:15Z: <powershell> tag was provided.. running powershell content
2022/11/05 06:27:22Z: User data script completed.
2022/11/05 06:34:45Z: Begin user data script process.
2022/11/05 06:34:45Z: Unable to parse <persist> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:34:45Z: Sending telemetry bool: IsUserDataScheduledPerBoot
2022/11/05 06:34:45Z: Unregister the scheduled task to persist user data.
2022/11/05 06:34:48Z: Unable to parse <runAsLocalSystem> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:34:48Z: Unable to parse <script> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:34:48Z: Unable to parse <powershellArguments> tags. This can happen when tags are unmatched or poorly formed.
2022/11/05 06:34:48Z: <powershell> tag was provided.. running powershell content
2022/11/05 06:35:01Z: Message: The output from user data script: Running User Data Script
(host) Running User Data Script
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Listener
Type Keys Name
---- ---- ----
Container {Transport=HTTPS, Address=*} Listener_123xxxxx
Setting up WinRM
(host) setting up WinRM
WinRM service is already running on this machine.
WinRM is not set up to allow remote access to this machine for management.
The following changes must be made:
...
...
...
2022/11/05 06:35:01Z: User data script completed.
2022/11/09 18:06:10Z: Begin user data script process.
2022/11/09 18:06:10Z: Failed to get metadata: The result from http://169.254.169.254/latest/user-data was empty
2022/11/09 18:06:18Z: Launch metadata did not include a user data script.
2022/11/09 18:06:18Z: User data script completed.
日志还显示了Failed to get metadata: The result from http://169.254.169.254/latest/user-data was empty
,当我浏览它用上面的powershell脚本返回的url时。
在原始AMI中是否有不允许运行用户数据的设置?为什么它不能运行PS脚本?
更新1
我在创建的实例上运行了以下命令,然后它运行了C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 –Schedule
因此,我可能需要在创建AMI的原始实例上运行这个命令,然后重新创建AMI并与terraform一起使用它。
参考https://aws.amazon.com/premiumsupport/knowledge-center/ec2-windows-troubleshoot-user-data/
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-windows-run-command-existing/
发布于 2022-11-14 10:48:56
这是一个为我解决问题的潜在解决方案(你在我上一篇文章中发表了评论)
构建AMI时,首先需要使用sysprep关闭系统。这可以在EC2Launch应用程序中找到。
本质上,如果没有sysprep,生成的EC2实例将没有启动时所需的初始网络规则。
https://stackoverflow.com/questions/74409522
复制相似问题