How to programmatically/remotely execute a program in EC2 Windows instance

后端 未结 5 1869
故里飘歌
故里飘歌 2020-12-08 03:13

I\'d like to launch an EC2 Windows instance, upload an EXEecutable & execute it (all in an automated fashion, this is important)

So far I was ab

5条回答
  •  伪装坚强ぢ
    2020-12-08 03:35

    The command ec2-run-instances has two additional arguments that can be used when running the command. The user-data command and user-data-file both of these perform the same task just they read from different input. When you use this argument the contents of the user-data will be uploaded to a amazon hosted URI http://169.254.169.254/1.0/user-data only available to the instance that was launched.

    The normal way to do this in the linux environment would be to upload a shell script to the instance to download the exe, your user-data-file might look something like this...

    #! /bin/bash
    wget http://www.domain.com/my-file.exe
    

    In Windows there's no default service installed to execute the user-data-file when the instance is booted but there is an open-source project CloudInit.NET which simulates the same process but with a powershell script. The only requirements are .NET 4.0 and CloudInit.NET. Once installed it will execute the user-data-file when the instance is booted. It's very easy to download a file and execute it with a powershell script.

    !# /powershell/
    $wc = New-Object System.Net.WebClient
    $wc.DownloadFile("http://www.domain.com/my-file.exe", "C:\my-file.exe");
    & 'C:\my-file.exe'
    

提交回复
热议问题