Cloudformation堆栈配置Windows EC2实例未安装所需的安装

时间:2019-11-20 20:27:31

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

我正在尝试使用执行堆栈的cloudformation模板在Windows ec2实例上安装git和vscode。堆栈成功完成,但是当我登录ec2实例时,没有看到安装git或vscode的信息。实际上,这些文件似乎没有下载到其各自的文件夹中。另外,我通过RDP使用默认的Administrator帐户登录ec2实例。

下面是我正在使用的cf模板。

Resources:
  EC2CustomInstanceSample:
    Type: 'AWS::EC2::Instance'
    Metadata:
      AWS::CloudFormation::Init:
        config:
          files:
            c:\cfn\cfn-hup.conf:
              content:
                Fn::Join:
                - ''
                - - "[main]\n"
                  - stack=
                  - Ref: AWS::StackId
                  - "\n"
                  - region=
                  - Ref: AWS::Region
                  - "\n"
            c:\cfn\hooks.d\cfn-auto-reloader.conf:
              content:
                Fn::Join:
                - ''
                - - "[cfn-auto-reloader-hook]\n"
                  - 'triggers=post.update'
                  - 'path=Resources.EC2CustomInstanceSample.Metadata.AWS::CloudFormation::Init'
                  - 'action=cfn-init.exe -v -s '
                  - Ref: AWS::StackId
                  - " -r EC2CustomInstanceSample"
                  - " --region "
                  - Ref: AWS::Region
                  - "\n"
            c:\cfn\modules\VSCodeSetup-x64-1.40.0.exe:
              sources:  https://az764295.vo.msecnd.net/stable/86405ea23e3937316009fc27c9361deee66ffbf5/VSCodeSetup-x64-1.40.0.exe
            c:\cfn\modules\Git-2.24.0.2-64-bit.exe:
              sources: https://github.com/git-for-windows/git/releases/download/v2.24.0.windows.2/Git-2.24.0.2-64-bit.exe
          commands:
            1-install-features:
              command:
                Fn::Join:
                - ''
                - - if not "None" EQU "
                  - Ref: Features
                  - "\" (servermanagercmd -install "
                  - Ref: Features
                  - " -restart)"
            2-install-vscode:
              command: powershell.exe -ExecutionPolicy RemoteSigned -Command Start-Process -FilePath C:\cfn\modules\VSCodeSetup-x64-1.40.0 -Args '/silent /install' -Verb RunAs -wait;            
            3-install-git:
              command: powershell.exe -ExecutionPolicy RemoteSigned -Command Start-Process -FilePath C:\cfn\modules\Git-2.24.0.2-64-bit -Args '/silent /install' -Verb RunAs -wait;            
          services:
            windows:
              cfn-hup:
                enabled: 'true'
                ensureRunning: 'true'
                files:
                - c:\cfn\cfn-hup.conf
                - c:\cfn\hooks.d\cfn-auto-reloader.conf
    Properties:
      InstanceType: !Ref InstanceType
      SecurityGroups:
        - !Ref InstanceSecurityGroupSample
      #KeyName: !Ref KeyName
      #KeyName: "ec2-sample"
      KeyName: "keypairsh"
      ImageId: "ami-028be67c2aa2f1ce1"
      UserData:
        Fn::Base64:
          Fn::Join:
          - ''
          - - "<script>\n"
            - 'cfn-init.exe -v -s '
            - Ref: AWS::StackId
            - " -r EC2CustomInstanceSample"
            - " --region "
            - Ref: AWS::Region
            - "\n"
            - "</script>"

感谢我在这里做错的任何更改或反馈。

0 个答案:

没有答案