How to Install AWS CLI V2
Install AWS CLI V2 for managing AWS services #
The AWS CLI (Command Line Interface) is a tool that lets you interact with Amazon Web Services through the command line. It allows you to manage AWS services, automate tasks, and access various AWS functionalities using commands typed into a terminal or command prompt.
Install AWS CLI #
To install follow the official installation instructions or run the install script.
Command line installation of AWS CLI #
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
Check the AWS CLI #
Check that the AWS CLI has been installed:
$ aws --version
aws-cli/2.13.38 Python/3.11.6 Linux/5.15.0-88-generic exe/x86_64.ubuntu.22 prompt/off
Configure AWS CLI Security #
Set the values you provide for the AWS Access Key ID and the AWS Secret Access Key. Values will be written to the shared credentials file (~/.aws/credentials) using the “default” profile.
$ aws configure
AWS Access Key ID [None]: BKA******************VK
AWS Secret Access Key [None]: VHYLs**************************9z4Ga
Default region name [None]:
Default output format [None]:
The AWS CLI credentials file #
AWS CLI uses ~/.aws/credentials file for storing the aws_access_key_id and aws_secret_access_key for each AWS account that it manages, the values are stored under [profile name]. The default profile is used when the user doesn’t specify a specific profile.
The file can be manually modified or the aws configure command can be used.
Example:
[default]
aws_access_key_id = AK************JT
aws_secret_access_key = HZJK****************************adsg12621a
[ditwl_infradmin]
aws_access_key_id = AK*************4
aws_secret_access_key = PI********************mc4
account_id = 12345678910
Execute aws configure help for advanced options.
Set a specific profile configuration for AWS CLI #
Create a new AWS CLI profile:
$ aws configure --profile ditwl-test
AWS Access Key ID [None]: AK*************4
AWS Secret Access Key [None]: PI********************mc4
Default region name [None]:
Default output format [None]:
The AWS CLI config file #
AWS CLI uses ~/.aws/config file for storing the advanced options for each AWS profile (in square brackets) that it manages, for example:
[profile ditwl_infradmin]
region = us-east-1
[default]
[profile ditwl-test]
Troubleshooting #
Kubectl shows an invalid apiVersion #
The Kubernetes kubectl command checks connectivity with all the clusters in the kubeconfig file, if any of the clusters is an Amazon EKS then it can show this error:
$ kubectl version
error: exec plugin: invalid apiVersion "client.authentication.k8s.io/v1alpha1"
Update the AWS CLI to the latest version with the install script and the --update option (sudo ./aws/install --update).
Can’t find aws binary #
When running the aws command: bash: /usr/bin/aws: No such file or directory, fix by following these instructions:
- Make sure that the AWS CLI is installed
- Clean the bash file cache so that the
awsbinary location is updated, runhash awsand test again