如何在 EC2 Windows 实例中以编程方式/远程执行程序 [英] How to programmatically/remotely execute a program in EC2 Windows instance

查看:14
本文介绍了如何在 EC2 Windows 实例中以编程方式/远程执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想启动一个 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 连接 &使用宏软件上传&执行文件,但根据之前的经验,至少可以说这是一种糟糕/脆弱的方法.

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!

Except that Windows doesn't have wget!

所以我的问题是:有没有办法以编程方式上传 &在 EC2 Windows 实例中执行 EXEcutable?

推荐答案

命令 ec2-run-instances 有两个额外的参数,可以在运行命令时使用.user-data 命令和 user-data-file 这两个命令执行相同的任务,只是从不同的输入读取.当您使用此参数时,用户数据的内容将上传到亚马逊托管的 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'

这篇关于如何在 EC2 Windows 实例中以编程方式/远程执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆