Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using start process to install awscli msi package on remote windows machine

I am trying to use packer to provision awscli on a Windows machine. To install the awscli is use the following PowerShell script:

$download_url = 'https://s3.amazonaws.com/aws-cli/AWSCLI64.msi'
$downloaddestination = 'C:\Program Files\awscli.msi'
$checkpath='C:\Program Files\Amazon\AWSCLI'
if (Test-Path $downloaddestination) {
  # // File exists do nothing
} else {
  # // File does not exist download it
  (New-Object System.Net.WebClient).DownloadFile($download_url, $downloaddestination)
}
$env:SEE_MASK_NOZONECHECKS = 1
Start-Process $downloaddestination /qn -Wait | Out-Null
Start-Sleep -Seconds 60
if (Test-Path $checkpath) {
  Write-Host "awscli installed"
} else {
  Write-Host "Installation failed"
}

I am unable to install awscli, its getting failed to install the MSI package even though its able to download the packege.

like image 573
krishna g Avatar asked Apr 12 '26 09:04

krishna g


1 Answers

I use Python to install the cli, it makes updating easier too. I normally use cloud formation, cloud formation uses the userdata to invoke a script that is run by powershell.

The script looks like this:

mkdir c:\setup-downloads
cd \setup-downloads
curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe
.\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
Start-Sleep -s 30
$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"
pip3 install awscli

Create a directory somewhere mkdir c:\setup-downloads . Change to that directory cd \setup-downloads I then use curl to download python: curl https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe --output python-inst.exe

Then I run the install using quiet mode, and I set it up to install itself into the path, and installed for everyone .\python-inst.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0

I wait for this to finish Start-Sleep -s 30 But you need to restart the powershell to actually access python so I run the following to set the environment variables:

$env:Path += ";C:\Program Files\Python37"
$env:Path += ";C:\Program Files\Python37\Scripts"

Now that I have python installed, and the environment variables configured I can install the cli as follows:

pip3 install awscli

If you run aws --version it works

like image 189
Jason Avatar answered Apr 14 '26 00:04

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!