Created
March 19, 2026 05:49
-
-
Save danilogco/022b8fa64dbb3b1c923e433d2c60ede1 to your computer and use it in GitHub Desktop.
Update all AWS clients (aws cli) - aws/kubectl/sam
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| readonly TMP_DIR="$(mktemp -d)" | |
| readonly ARCH="$(uname -m)" | |
| AWS_ARCH="" | |
| K8S_ARCH="" | |
| SAM_ARCH="" | |
| cleanup() { | |
| rm -rf "$TMP_DIR" | |
| } | |
| set_architectures() { | |
| case "$ARCH" in | |
| x86_64|amd64) | |
| AWS_ARCH="x86_64" | |
| K8S_ARCH="amd64" | |
| SAM_ARCH="x86_64" | |
| ;; | |
| aarch64|arm64) | |
| AWS_ARCH="aarch64" | |
| K8S_ARCH="arm64" | |
| SAM_ARCH="arm64" | |
| ;; | |
| *) | |
| echo "Unsupported architecture: $ARCH" | |
| exit 1 | |
| ;; | |
| esac | |
| } | |
| require_commands() { | |
| local cmd | |
| for cmd in "$@"; do | |
| if ! command -v "$cmd" >/dev/null 2>&1; then | |
| echo "$cmd not found. Install it before continuing." | |
| exit 1 | |
| fi | |
| done | |
| } | |
| get_aws_current_version() { | |
| if command -v aws >/dev/null 2>&1; then | |
| aws --version 2>&1 | awk -F/ '{print $2}' | awk '{print $1}' | |
| else | |
| echo "none" | |
| fi | |
| } | |
| get_sam_current_version() { | |
| if command -v sam >/dev/null 2>&1; then | |
| sam --version | awk '{print $4}' | |
| else | |
| echo "none" | |
| fi | |
| } | |
| get_kubectl_current_version() { | |
| if command -v kubectl >/dev/null 2>&1; then | |
| kubectl version --client -o json 2>/dev/null | jq -r '.clientVersion.gitVersion' | sed 's/^v//' | |
| else | |
| echo "none" | |
| fi | |
| } | |
| install_aws() { | |
| echo "Updating AWS CLI..." | |
| curl -fsSL "https://awscli.amazonaws.com/awscli-exe-linux-${AWS_ARCH}.zip" -o "$TMP_DIR/awscliv2.zip" | |
| unzip -q "$TMP_DIR/awscliv2.zip" -d "$TMP_DIR" | |
| sudo "$TMP_DIR/aws/install" --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update | |
| echo "AWS CLI updated:" | |
| aws --version | |
| } | |
| install_kubectl() { | |
| local stable_version | |
| stable_version="$(curl -fsSL https://dl.k8s.io/release/stable.txt)" | |
| echo "Updating kubectl..." | |
| curl -fsSL "https://dl.k8s.io/release/${stable_version}/bin/linux/${K8S_ARCH}/kubectl" -o "$TMP_DIR/kubectl" | |
| chmod +x "$TMP_DIR/kubectl" | |
| sudo mv "$TMP_DIR/kubectl" /usr/local/bin/kubectl | |
| echo "kubectl updated:" | |
| kubectl version --client | |
| } | |
| install_sam() { | |
| echo "Updating SAM CLI..." | |
| curl -fsSL "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-${SAM_ARCH}.zip" -o "$TMP_DIR/aws-sam-cli.zip" | |
| unzip -q "$TMP_DIR/aws-sam-cli.zip" -d "$TMP_DIR/sam-install" | |
| sudo "$TMP_DIR/sam-install/install" --update | |
| echo "SAM CLI updated:" | |
| sam --version | |
| } | |
| trap cleanup EXIT | |
| require_commands curl unzip awk jq sudo | |
| set_architectures | |
| echo | |
| echo "########################################" | |
| echo "# AWS CLI" | |
| echo "########################################" | |
| AWS_CURRENT="$(get_aws_current_version)" | |
| AWS_LATEST="$(curl -fsSL https://api.github.com/repos/aws/aws-cli/tags | jq -r '.[0].name' | sed 's/^v//')" | |
| if [[ "$AWS_CURRENT" == "none" ]]; then | |
| echo "AWS CLI not found." | |
| else | |
| echo "Installed version: $AWS_CURRENT" | |
| fi | |
| if [[ "$AWS_CURRENT" == "$AWS_LATEST" ]]; then | |
| echo "AWS CLI is already up to date." | |
| else | |
| install_aws | |
| fi | |
| echo | |
| echo "########################################" | |
| echo "# Kubectl CLI" | |
| echo "########################################" | |
| KUBECTL_CURRENT="$(get_kubectl_current_version)" | |
| KUBECTL_LATEST="$(curl -fsSL https://dl.k8s.io/release/stable.txt | sed 's/^v//')" | |
| if [[ "$KUBECTL_CURRENT" == "none" ]]; then | |
| echo "kubectl not found." | |
| else | |
| echo "Installed version: $KUBECTL_CURRENT" | |
| fi | |
| if [[ "$KUBECTL_CURRENT" == "$KUBECTL_LATEST" ]]; then | |
| echo "kubectl is already up to date." | |
| else | |
| install_kubectl | |
| fi | |
| echo | |
| echo "########################################" | |
| echo "# SAM CLI" | |
| echo "########################################" | |
| SAM_CURRENT="$(get_sam_current_version)" | |
| SAM_LATEST="$(curl -fsSL https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r '.tag_name' | sed 's/^v//')" | |
| if [[ "$SAM_CURRENT" == "none" ]]; then | |
| echo "SAM CLI not found." | |
| else | |
| echo "Installed version: $SAM_CURRENT" | |
| fi | |
| if [[ "$SAM_CURRENT" == "$SAM_LATEST" ]]; then | |
| echo "SAM CLI is already up to date." | |
| else | |
| install_sam | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment