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 able to programmatically launch EC2 Windows instance & get its parameters (password / IP), now I’d like to find a way to upload this Executable (from my Windows machine or from my other EC2 linux instance) & run it.
I thought about launching an RDP connection & using a macro software to upload & execute the file, but based on previous experiences this is a poor/fragile approach to say the least.
I also thought about uploading this EXE to a server, then do something like this on Windows:
wget http://www.domain.com/my-file.exe
Except that Windows doesn’t have wget!
So my question is: is there a way to programmatically upload & execute an EXEcutable in EC2 Windows instance?
The command
ec2-run-instanceshas two additional arguments that can be used when running the command. Theuser-datacommand anduser-data-fileboth 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 URIhttp://169.254.169.254/1.0/user-dataonly 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…
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.