AWS CLI supports multiple platforms like Windows, Linux, and macOS and provides direct access to public APIs for AWS. Further, automation of tedious infrastructure tasks is easily possible in a CLI environment.
AWS CLI Versions
AWS CLI has two major versions available, i.e., version 1.x, which is available for backward compatibility while version 2.x is the current general release available and is intended for production use. It’s not completely backward compatible and hence scripts that use version 1 of AWS CLI may not be compatible with version 2.
Install AWS CLI
Here we’ll be covering the installation of AWS CLI on different platforms. Since version 2.x is the general release available at the time of this writing we’ll be only covering the installation of the same.
Linux
To install the latest version of AWS CLI on Linux x86 (64-bit), use the following commands: To confirm successful installation, run:
macOS
macOS installation of AWS CLI is officially offered in GUI as well CLI methods. To go the GUI way, download the latest version of the AWS CLI package from the following link: https://awscli.amazonaws.com/AWSCLIV2.pkg and double click the downloaded package to launch the installer. Follow the on-screen instructions to complete the installation. Most of the options can be left as default for normal installation requirements. If you want to install using CLI way, on a new terminal issue below commands to download and install the latest AWS CLI version: sudo in above command is needed if you plan to install it system-wide. If you want to install as a local user without admin rights, there’s a simple official workaround. You need to create a XML file that will provide a path /Users/myusername where you want AWS CLI to be installed. This path should be an existing directory or created before launching the installer else it’ll fail. Then you can proceed to download the latest installation package using curl as: Once you have the package and the XML configuration file ready, AWS CLI can be installed for the local user using: Here AWSCLIV2.pkg is the package that we downloaded in an earlier step using curl and -target specifies that installation is for local user and -applyChoiceChangesXML basically indicates to the installer that we’ll be using custom choices that contain our relative installation path /Users/myusername or whatever the local directory path has been specified in the XML. As the last step, run the following commands to create the required symlinks which are required by AWS CLI to work correctly. If your $PATH includes a directory that you can write to and you specify that directory as the target’s path, you can run the above command without sudo. But if you don’t have a writable directory in your $PATH, you must use sudo for permissions to write to the specified target folder. The default location for a symlink is /usr/local/bin/. To verify the install, use:
Windows
For a Windows install, AWS CLI v2 requires a Windows 64-bit version or later and admin rights for installation. The latest Windows installation package can be downloaded from: https://awscli.amazonaws.com/AWSCLIV2.msi and launched with admin rights for installation to complete. Alternatively, you can use misexec in CLI to install on the command line as: You can use aws –version in a command prompt to verify the install.
Docker
Finally, if you don’t want to install AWS CLI on your local OS and happen to have access to Docker, it is just a matter of single command to execute AWS CLI commands as: where command is the AWS CLI command to execute. The above command will launch a container with the required AWS CLI setup and will directly proceed to execute the specified command and exit once it’s done. There’s a bunch of options to use your existing AWS CLI credentials, configuration, and environment variables as an input for the container that makes it all the more usable and portable. There’s also an alias option to shorten the long docker command to something simple and comprehensible like for Linux host use: Make sure to add the above command in your shell’s profile file for persistence. Once done, you can use it like: Easy and looks better. Read more about AWS CLI Docker-based offering and possibilities here.
Summary
AWS CLI offers a command-based experience to manage your AWS infrastructure with ease of control especially with repetitive tasks and ultimately opens the door for automation and managing Infrastructure as Code (IaC). You learned about how to install it on different platforms. As a next step, you can read here on how to configure it to use it with your AWS account.