Skip to content

Instantly share code, notes, and snippets.

@jamesls
Last active January 15, 2023 21:52
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jamesls/3623e9589db175509ec2c61536b6c6b9 to your computer and use it in GitHub Desktop.
Save jamesls/3623e9589db175509ec2c61536b6c6b9 to your computer and use it in GitHub Desktop.
AWS CLI v2 upgrade aliases.
[toplevel]
# Put this in ~/.aws/cli/alias
# and you'll have an "aws upgrade"
# and an "aws check-upgrade" command.
#
# Only works on macOS and installs using
# the .pkg installer.
#
upgrade = !f() {
curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "/tmp/AWSCLIV2.pkg"
sudo installer -pkg /tmp/AWSCLIV2.pkg -target /
rm -f /tmp/AWSCLIV2.pkg
}; f
# This version doesn't work on >= Catalina 10.15, use the alternate
# implementation below.
#
# check-upgrade = !f() {
# rm -f /tmp/AWSCLIV2.pkg
# latest_cli_version=$(curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o - | \
# tar xOv - 2>/dev/null | \
# grep -a '<pkg-info' | \
# sed "s#.* version=\"\([0-9\.]*\)\".*#\1#")
# release_date=$(curl -sI "https://awscli.amazonaws.com/AWSCLIV2.pkg" | \
# grep 'Last-Modified' | cut -d':' -f 2- | tr '\r\n' ' ')
# echo "Current version: $(aws --version | cut -d' ' -f 1)"
# echo " New version: aws-cli/${latest_cli_version} (${release_date})"
# }; f
# This version works on Catalina (10.15) and higher.
#
check-upgrade = !f() {
rm -f /tmp/AWSCLIV2.pkg
curl -s "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "/tmp/AWSCLIV2.pkg"
(cd /tmp/ && xar -x --exclude Distribution --exclude Resources -f /tmp/AWSCLIV2.pkg)
latest_cli_version=$(grep -a '<pkg-info' < /tmp/aws-cli.pkg/PackageInfo | \
sed "s#.* version=\"\([0-9\.]*\)\".*#\1#")
release_date=$(curl -sI "https://awscli.amazonaws.com/AWSCLIV2.pkg" | \
grep 'Last-Modified' | cut -d':' -f 2- | tr '\r\n' ' ')
echo "Current version: $(aws --version | cut -d' ' -f 1)"
echo " New version: aws-cli/${latest_cli_version} (${release_date})"
}; f
install-version = !f() {
curl -s "https://awscli.amazonaws.com/AWSCLIV2-$1.pkg" -o "/tmp/AWSCLIV2.pkg"
sudo installer -pkg /tmp/AWSCLIV2.pkg -target /
rm -f /tmp/AWSCLIV2.pkg
}; f
@sebsto
Copy link

sebsto commented Jul 10, 2020

There is a missing section header in this file. Please add [toplevel] on line 1. Thanks !

@jamesls
Copy link
Author

jamesls commented Aug 7, 2020

Thanks!

@dasgoll
Copy link

dasgoll commented Aug 8, 2020

Worked like a charm. Thank you 👍

@0xf2
Copy link

0xf2 commented Jan 15, 2023

Is there a similar versioned path for the Linux zip-based installer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment