3

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
krishna g
  • 461
  • 1
  • 5
  • 15
  • AFAICS the command should work, assuming that it's actually being run on a remote host (there's nothing in the code you posted that would do this). First troubleshooting measure would probably be to have the installer create a log (add the parameter `/l*v C:\awscli.log`). – Ansgar Wiechers May 01 '16 at 20:12
  • the remote host is user specific should i need to mention the user id and pwd – krishna g May 01 '16 at 20:18
  • You can obfuscate that information. – Ansgar Wiechers May 01 '16 at 20:19
  • i am getting the follwoing error for the command i used Start-Process 'C:\Program Files\awscli.msi' /qn -Wait /l*v C:\awscli.log | out-null A positional parameter cannot be found that accepts argument '/l*v' – krishna g May 01 '16 at 20:27
  • It's `/l*v`, and you need to pass the argument list for the installer as an array (`/qn,/l*v,C:\awscli.log`) or as a string (`"/qn /l*v C:\awscli.log"`). – Ansgar Wiechers May 01 '16 at 21:13
  • as part of logs found the following error code `Message` FROM `Error` WHERE `Error` = 1709 MSI (s) (88:E4) [03:26:02:150]: Product: AWS Command Line Interface -- Access is denied. Access is denied. – krishna g May 02 '16 at 07:38
  • the detailed log i have posted below take a look – krishna g May 02 '16 at 07:39
  • Please DO NOT post information pertaining to your question as an answer. Use the edit link right below your question to include additional information in your question. – Ansgar Wiechers May 02 '16 at 09:08

4 Answers4

1

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

Jason
  • 2,555
  • 2
  • 16
  • 17
1

I tried @Jasons answer, calling the PowerShell file from an autoattend syncronusCommand block, however, I could not get pip3 command to be recognised.. setting the python env path inline I felt was a little hacky.

Check out - https://www.python.org/download/releases/2.5/msi/ - which explains that when using an MSI file the - installation can be initiated programmatically.

My PowerShell file now looks like this

Invoke-WebRequest -Uri https://awscli.amazonaws.com/AWSCLIV2.msi -Outfile "C:\aws.msi"
Start-Process -Wait -FilePath msiexec -ArgumentList /i, "c:\aws.msi", /qn

Now I have automated the install of aws cli on windows server.

Guy Rawsthorn
  • 189
  • 1
  • 4
  • This is the ticket. No need for another language run-time, just run those two lines in your script! – Ari Jun 08 '21 at 03:17
-3

I would suggest changing the approach and installing aws cli via pip the Python package manager that comes with the default Python installation. Follow this guide to install Python silently on windows. Then you can just run the command below and it will install the awscli.

pip install awscli
Shimon Tolts
  • 1,602
  • 14
  • 15
  • can you explain in detail, i think pip cannot be installed in windows, if yes please do explain full procedure – krishna g May 01 '16 at 19:57
-4

You can use pip on windows, it's easy:

1. download and Install Python 2.7 for Win x64 in Python27 folder (default) [I had trouble with Python3.0 but I may have installed it wrong] https://www.python.org/downloads/

2. in control panel, system, advanced settings add (ie., "new") to the user or system variable:
PYTHONPATH %PYTHONPATH%;C:\Python27\Lib

3. in control panel, system, advanced settings, edit the system PATH variable and add at the end:

;C:\Python27;C:\Python27\Scripts;C:\Program Files\Amazon\AWSCLI\
4. download the awscli package from https://s3.amazonaws.com/aws-cli/AWSCLI64.msi

5. now you can run in the Windows DOS Command box: "pip install --upgrade awscli"

6. you can run cli commands in Windows DOS Command box, powershell or powershell ise. First run "aws configure" in powershell or win/dos command box

7. then you can run any CLI or CLI SDK command in powershell ise

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58