0

Ich versuche, codedeploy-agent.msi zu einer ec2-Instanz bereitzustellen (win 2012). Sein hinter einem privaten Subnetz mit NO NAT gateway, aber mit S3 endpoint, ich testete dieses powershell.exe -Command Read-S3Object -BucketName aws-codedeploy-us-west-2 -Key latest/codedeploy-agent.msi -File codedeploy-agent.msi funktioniert. Der Agent wird über die Powershell von der ec2-Instanz heruntergeladen.Kann codedeploy-agent.msi nicht mit Cloudformation installieren

Mit dem Skript cloudfromation wird die Instanz jedoch erstellt, ohne dass der Agent installiert ist. Es fehlen die Ordner c: \ cfn und cfn-init.log. Was könnte das Problem sein ???

"WorkerInstance": { 
      "Type": "AWS::EC2::Instance", 
      "Metadata": { 
       "AWS::CloudFormation::Init": { 
        "config": { 
         "commands": { 
          "00-download-host-agent": { 
           "command": { 
            "Fn::Join": [ 
             "", 
             [ 
              "powershell.exe -Command \"Read-S3Object ", 
              "-BucketName aws-codedeploy-us-west-2 ", 
              "-Key latest/codedeploy-agent.msi ", 
              "-File codedeploy-agent.msi\"" 
             ] 
            ] 
           }, 
           "cwd": "C:/cfn", 
           "waitAfterCompletion" : 0 
          }, 
          "01-install-host-agent": { 
           "command": "C:\\cfn\\codedeploy-agent.msi /quiet /l C:\\cfn\\host-agent-install-log.txt", 
           "ignoreErrors": "true", 
           "waitAfterCompletion" : 0 
          }, 
          "02-signal-ready": { 
           "command": { 
            "Fn::Join": [ 
             "", 
             [ 
              "\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-signal\"", 
              " -e 0 \"", 
              "\"" 
             ] 
            ] 
           } 
          } 
         }, 
         "services": { 
          "windows": { 
           "codedeploy-agent": { 
            "enabled": "true", 
            "ensureRunning": "true", 
            "commands": [ 
             "01-install-host-agent" 
            ] 
           } 
          } 
         } 
        } 
       } 
      }, 
      "Properties": { 
       "DisableApiTermination": "false", 
       "InstanceInitiatedShutdownBehavior": "stop", 
       "IamInstanceProfile": { 
          "Ref": "IAMRole" 
         }, 
       "ImageId": "ami-c55089bd", 
       "InstanceType": "t2.medium", 
       "KeyName": "mykey", 
       "Monitoring": "true", 
       "Tags": [{ 
         "Key": "CodeDeployGroup", 
         "Value": { 
          "Fn::Join": ["-", ["app", { 
             "Ref": "EnvType" 
            }, { 
             "Ref": "EnvVersion" 
            }, "CodeDeployGroup" 
           ]] 
         } 
        }, { 
         "Key": "Name", 
         "Value": { 
          "Fn::Join": ["-", ["App", { 
             "Ref": "EnvType" 
            }, { 
             "Ref": "EnvVersion" 
            }, "Worker" 
           ]] 
         } 
        } 
       ], 
         "NetworkInterfaces": [{ 
         "DeleteOnTermination": "true", 
         "Description": "Primary network interface", 
         "DeviceIndex": 0, 
         "SubnetId": "subnet-70234568", 
         "GroupSet": ["sg-8affd7", "sg-fdffsfsd4"] 
        } 
       ] 
      } 
     } 

Antwort

0

Ich bin mir nicht sicher, warum es nicht funktioniert. Ich habe es endlich zum Laufen gebracht, indem ich es als userdata-Skript eingefügt habe.

"UserData": { 
        "Fn::Base64": { 
          "Fn::Join": ["", ["<script>\n", "mkdir c:\\cfn\n", "mkdir c:\\cfn\\log\n", 
           "powershell.exe Read-S3Object -BucketName aws-codedeploy-us-west-2/latest -Key codedeploy-agent.msi -File c:\\cfn\\codedeploy-agent.msi\n", 
           "c:\\cfn\\codedeploy-agent.msi /quiet /l c:\\cfn\\host-agent-install-log.txt\n", 
           "c:\\\"Program Files\"\\Amazon\\cfn-bootstrap\\cfn-init.exe -s ", { 
            "Ref": "AWS::StackName" 
           }, " --region ", { 
            "Ref": "AWS::Region" 
           }, " > c:\\cfn\\log\\cfn-call-log 2>&1", "</script>"]]      
        } 
       }, 

Dies installiert den Agenten sowie aktiviert und startet den Dienst.

1

Der Befehl sieht gut aus. Sie können versuchen, eine Ausführungsrichtlinie für den Powershell-Befehl anzugeben. Diese CFN-Vorlagen funktionieren für mich:

 "WorkerInstance" : { 
      "Type" : "AWS::EC2::Instance", 
      "Metadata" : { 
       "AWS::CloudFormation::Init" : { 
        "config" : { 
         "commands" : { 
          "00-download-host-agent" : { 
           "command" : {"Fn::Join" : [ "", [ 
            "powershell.exe -executionpolicy remotesigned -Command \"Read-S3Object ", 
            "-BucketName aws-codedeploy-us-west-2 ", 
            "-Key latest/codedeploy-agent.msi ", 
            "-File codedeploy-agent.msi\"" 
           ]]}, 
           "cwd" : "C:/cfn", 
           "waitAfterCompletion" : 0 
          }, 
          "01-install-host-agent" : { 
           "command" : "C:\\cfn\\codedeploy-agent.msi /quiet /l C:\\cfn\\host-agent-install-log.txt", 
           "ignoreErrors" : "true", 
           "waitAfterCompletion" : 0 
          }, 
          "02-signal-ready" : { 
           "command" : { 
            "Fn::Join" : [ "", [ 
             "\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-signal\"", 
             " -e 0 \"", 
             { "Ref" : "WaitHandle" }, 
             "\"" 
            ]] 
           }, 
           "waitAfterCompletion" : 0 
          } 
         }, 
         "services" : { 
          "windows" : { 
           "codedeploy-agent" : { 
            "enabled" : "true", 
            "ensureRunning" : "true", 
            "commands" : [ "01-install-host-agent" ] 
           } 
          } 
         } 
        } 
       } 
      },