lightsail Launch script使用示例(以给lightsail Windows实例预装chrome为例)
最近在使用lightsail创建Windows实例时遇到一个问题,就是如何在创建机器时自动预装chrome呢?有时一下子要创建几十台机器,如果一台一台手动安装将会是很痛苦的事情。其实有个很好的办法,即通过Launch script来解决这个问题。
这里以Windows Server 2012 R2系统为例,创建实例时,在Launch script下输入以下脚本即可:
<powershell>
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "https://dl.google.com/chrome/install/latest/chrome_installer.exe" -OutFile $Path$Installer; Start-Process -FilePath $Path$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path$Installer
</powershell>
等待一段时间,连接到你的Windows实例就会发现chrome已经自动安装好了:
同理,安装Firefox的脚本可以是:
<powershell>
$Path = $env:TEMP; $Installer = "Firefox Installer.exe"; Invoke-WebRequest "https://download-installer.cdn.mozilla.net/pub/firefox/releases/62.0.3/win32/en-US/Firefox%20Installer.exe" -OutFile $Path$Installer; Start-Process -FilePath $Path$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path$Installer
</powershell>
另外,ec2创建Windows实例也可以使用上述脚本:
如果要安装其他软件,可以自行更改脚本。