【问题标题】:Userdata not working in Custom AMI (built on Windows 2019 Base AMI)?用户数据在自定义 AMI(基于 Windows 2019 基础 AMI)中不起作用?
【发布时间】:2021-08-26 07:03:10
【问题描述】:

我正在使用基于 Windows 2019 Base AMI (ami-0fa60543f60171fe3) 构建的自定义 AMI 来创建 Windows 服务器。但我看到用户数据不起作用。这是我正在使用的 CFT。

RabbitMQServer:
    Type: AWS::EC2::Instance
    Properties:
      KeyName: !Ref PublicKeyName
      IamInstanceProfile: !Ref IamInstanceProfile      
      ImageId: !Ref RabbitMQServerAMI 
      InstanceType: !Ref RabbitMQServerInstanceType
      Monitoring: true
      SecurityGroupIds:
        - !Ref PrivateInstanceSG
      SubnetId: !Ref PrivateSubnetID 
      UserData: !Base64 |
          <script>
          echo Current date and time >> C:\test.log
          echo %DATE% %TIME% >> C:\test.log
          </script>
          <persist>true</persist>

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-cloudformation


    【解决方案1】:

    在 Windows 中,出于安全原因,此任务在首次运行后会被禁用。要启用它,请执行以下命令,

    C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 –Schedule
    

    但是,使用 persist 标签会导致 Invoke-UserData 通过 Register-FunctionScheduler 安排单独的任务,以便在后续启动时保留您的用户数据。你可以在C:\ProgramData\Amazon\EC2-Windows\Launch\Module\Scripts\Invoke-Userdata.ps1.看到这个自己。

    供进一步分析 如果您的用户数据脚本有其他问题,您可以在C:\ProgramData\Amazon\EC2-Windows\Launch\Log\UserdataExecution.log(这是一个隐藏文件夹)找到用户数据执行日志

    其他选项请参考https://blog.kloud.com.au/2017/04/23/re-execute-the-userdata-script-in-an-aws-windows-instance/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-21
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-06
      • 1970-01-01
      相关资源
      最近更新 更多