微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

用于 Windows 安装 java 的 Cf 模板不起作用

如何解决用于 Windows 安装 java 的 Cf 模板不起作用

AWS 新手。尝试使用下面的 CF 模板在 Windows 机器上安装 Java。堆栈运行正常,但未安装 Java。我也没有看到从我的 s3(私有)复制到 C 驱动器上的任何文件。有人可以帮我找出问题吗?

AWstemplateFormatVersion: 2010-09-09
Description: "Cloud Formation template snippet to install Java JDK on Windows"
Metadata: {}
Parameters: {}
Rules: {}
Mappings: {}
Resources:
  JavaSeleniumEC2Instance:
    Type: "AWS::EC2::Instance"
    Properties:
      KeyName: "windowskeypair"
      ImageId: ami-0229f7666f517b31e
      InstanceType: "t2.micro"
      SecurityGroups:
        - "windows"
      IamInstanceProfile: "EC2_Access_S3"
      UserData:
        Fn::Base64: !Sub |
           "<script> \\n cfn-init.exe -v -s ${AWS::StackId} -r JavaSeleniumEC2Instance --region ${AWS::Region} \\n </script>"
    Metadata:
      AWS::CloudFormation::Authentication:
          S3AccessCreds:
            type: "S3"
            buckets:
              - "windowsartifcats"
            roleName: "EC2_Access_S3"
      AWS::CloudFormation::Init:
          config:
            files:
              c:\\jdk-11.0.9_windows-x64_bin.exe:
                source: "https://windowsartifcats.s3.amazonaws.com/jdk-11.0.9_windows-x64_bin.exe"
              c:\\selenium:
                source: "https://windowsartifcats.s3.amazonaws.com/selenium-server-standalone-3.141.59.jar"
              c:\\iedriver:
                source: "https://windowsartifcats.s3.amazonaws.com/IEDriverServer.exe"
              c:\\Install-Java-JDK.ps1:
                content: !Join
                  - ''
                  - - 'Set-Location C:\\;'
                    - '.\\jdk-11.0.9_windows-x64_bin.exe /s'

            commands:
              command: "powershell.exe -ExecutionPolicy RemoteSigned -Command c:\\Install-Java-JDK.ps1"
              waitAfterCompletion: '180'

从 C:\ProgramData\Amazon\EC2-Windows\Launch\log 中的 UserDataExecution.log 登录

2020/12/19 22:46:00Z: Message: The errors from user scripts: The filename,directory name,or volume label Syntax is incorrect.

2020/12/19 22:46:00Z: Message: The output from user scripts: 
C:\Windows\system32>\\n cfn-init.exe -v -s arn:aws:cloudformation:us-east-1:752996075730:stack/stack21/978a8470-424b-11eb-a497-0e0d04c7a1a5 -r JavaSeleniumEC2Instance --region us-east-1 \\n  

2020/12/19 22:46:00Z: Userdata execution done

另外,我在 Ec2 实例的 powershell 中手动运行了以下命令(不确定它是否是正确的调试方式),这给了我以下错误

PS C:\Users\Administrator> cfn-init.exe -v -s arn:aws:cloudformation:us-east-1:752996075730:stack/stack21/978a8470-424b-11eb-a497-0e0d04c7a1a5 -r JavaSeleniumEC2Instance --region us-east-1
Error occurred during build: command does not specify the 'command' attribute,which is required
PS C:\Users\Administrator>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。