如何编程/远程执行的EC2 Windows实例程序实例、程序、Windows

2023-09-11 08:05:32 作者:  ? 空城旧梦 %

我想推出一个EC2 Windows实例,上传EXEecutable和放大器;执行它(所有的自动方式,这很重要)

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

到目前为止,我可以以编程方式启动EC2 Windows实例和放大器;得到其参数(密码/ IP),现在我想找到一种方法来上传此可执行文件(从我的Windows机器或从我的其他EC2 Linux实例的 )及运行它。

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.

我想过推出的RDP连接和放大器;使用宏软件上传和放大器;执行该文件,但基于previous的经验,这是一个贫穷/脆弱的办法,至少可以说。

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.

我也想过上传这个EXE到服务器,然后做这样的事情在Windows上:

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

在Windows平台的不的带有wget!

所以我的问题是:有没有办法以编程方式上传和放大器;在EC2 Windows实例执行的可执行文件?

推荐答案

命令 EC2-运行实例具有可运行命令时,可以使用两个额外的参数。该用户数据命令和用户数据文件这两个执行只是,他们从不同的输入读取相同的任务。当您使用此参数,用户数据的内容将被上传到托管的URI亚马逊 http://169.254.169.254/1.0/user-data 只提供给实例推出。

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.

正常的方式来做到这一点在Linux环境下将是一个shell脚本上传到实例下载exe文件,您的用户数据文件可能是这个样子......

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

在Windows中有安装到执行用户数据文件时,该实例启动时没有默认的服务,但有一个开放源代码项目的 CloudInit.NET 它模拟同样的过程,但用PowerShell脚本。唯一的要求是.NET 4.0和CloudInit.NET。安装完毕后,将执行用户数据文件时,该实例启动时。这是很容易下载一个文件,并用PowerShell脚本执行它。

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'