Skip to main content
Question

Trouble installing AWS CLI version 2


rpayne
Forum|alt.badge.img+11

Ok, Let me preface this by first stating that scripting is NOT my strong point.
I'm attempting to install AWS CLI version 2 for all users per the instructions on:

https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html#cliv2-mac-install-cmd

Attempting to run the commands via policy result in an exit code 127. I've found a few posts about AWSCLI version 1, but none of the solutions seem to work. Any suggestions?

7 replies

Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • December 16, 2020

@rpayne Could you post your script, please?


Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • December 16, 2020

@rpayne Just put a rough script based on the AWS info.

#!/bin/bash

#  download the AWSCLIV2.pkg to tmp folder and return the http_code
response=$(/usr/bin/curl --silent --write-out "%{http_code}" "https://awscli.amazonaws.com/AWSCLIV2.pkg" --output /tmp/AWSCLIV2.pkg)

checkForV1() {
  # https://docs.aws.amazon.com/cli/latest/userguide/install-macos.html#install-macosos-bundled-uninstall
  # Uninstall the AWS CLI version 1 bundled installer
  # The bundled installer puts everything inside of the installation directory except the optional symlink, so to uninstall, you just need to delete those two items.

  if [[ -d  /usr/local/aws  ]]; then
    echo  "AWD CLI version 1 found"
    /bin/rm -rf /usr/local/aws
    /bin/rm /usr/local/bin/aws
  else
    echo  "AWD CLI version 1 not found"
  fi

}


# check if the download was successful
if [[ $response -eq 200  ]]; then
  echo "package downloaded"

  # https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-mac.html
  # Important
  # AWS CLI versions 1 and 2 use the same aws command name. If you have both versions installed, your computer uses the first one found in your search path. If you previously installed AWS CLI version 1, we recommend that you do one of the following to use AWS CLI version 2:
  # Recommended – Uninstall AWS CLI version 1 and use only AWS CLI version 2.
  checkForV1

  # install the package
  /usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1

  # clean up
  /bin/rm /tmp/AWSCLIV2.pkg

else
  echo "download error: $response"
  # exit the curl download code so we can see in the Jamf reports where it is failing.
  exit $response
fi

exit 0

Tested on 10.15.6 VM and looks OK


Forum|alt.badge.img+4
  • Contributor
  • 13 replies
  • May 25, 2021

@Mauricio Hey, thanks for the script.

I seem to be getting the following after it installs successfully.

Running script Install AWS CLI 2...
Script exit code: 1
Script result: package downloaded
AWD CLI version 1 not found
installer: Package name is AWS Command Line Interface
installer: Upgrading at base path /
installer: The upgrade was successful.
Error running script: return code was 1.


Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • May 25, 2021

@kissland Try to change the line of the installer.

from

/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target / || echo "Ops! Problem with the installer" ; exit 1

to

/usr/sbin/installer -pkg /tmp/AWSCLIV2.pkg -target /

You will be able to get the installer output in the log.
Hope that helps.
Regards


Forum|alt.badge.img+4
  • Contributor
  • 13 replies
  • May 25, 2021

@Mauricio Seems to work now, how can I check whether the $response returns anything? After running the script in terminal, when I run $response its just blank


Mauricio11
Forum|alt.badge.img+11
  • Valued Contributor
  • 173 replies
  • May 26, 2021

@kissland Not sure if I understand the question.

If you run the curl command in Terminal that variable will be available

If you run the script in the Terminal then the "package downloaded" is the clue that $response was 200, that variable is only available to the script.

Does it make sense?
Regards


Mcleveland
Forum|alt.badge.img+7
  • New Contributor
  • 9 replies
  • February 8, 2024

A lot has changed during this time, but just in case anyone goes to this post:

https://github.com/Installomator/Installomator <--- would be a good resource to use


awscli2) # credit: Bilal Habib (@Pro4TLZZ) name="AWSCLI" type="pkg" packageID="com.amazon.aws.cli2" downloadURL="https://awscli.amazonaws.com/AWSCLIV2.pkg" appNewVersion=$( curl -fs "https://raw.githubusercontent.com/aws/aws-cli/v2/CHANGELOG.rst" | grep -i "CHANGELOG" -a4 | grep "[0-9.]" ) expectedTeamID="94KV3E626L" ;;

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings