Skip to content

Instantly share code, notes, and snippets.

@matootie
Created March 5, 2022 16:52
Show Gist options
  • Select an option

  • Save matootie/f091837d21a903f9857bf61e1b8fb5e3 to your computer and use it in GitHub Desktop.

Select an option

Save matootie/f091837d21a903f9857bf61e1b8fb5e3 to your computer and use it in GitHub Desktop.
Install AWS CLI v2 in a Docker development container for Visual Studio Code.
#!/usr/bin/env bash
set -e
# Ensure script is run as root.
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# Function to run apt-get if needed
apt_get_update_if_needed()
{
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update
else
echo "Skipping apt-get update."
fi
}
# Checks if packages are installed and installs them if not
check_packages() {
if ! dpkg -s "$@" > /dev/null 2>&1; then
apt_get_update_if_needed
apt-get -y install --no-install-recommends "$@"
fi
}
# Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive
# Check for dependencies.
check_packages curl wget unzip
# Determine the architecture to know the distributable.
architecture="$(dpkg --print-architecture)"
if [ $architecture = "arm64" ]; then
dist=aarch64
elif [ $architecture = "amd64" ]; then
dist=x86_64
fi
# Download the AWS CLI installer.
curl https://awscli.amazonaws.com/awscli-exe-linux-$dist.zip -o /tmp/awscli.zip
# Unzip the AWS CLI installer.
unzip /tmp/awscli.zip -d /tmp
# Run the install script.
sh /tmp/aws/install
# Remove the installer files.
rm -rv /tmp/aws /tmp/awscli.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment