published: 23rd of April 2020
In this post I will show you how to get the AWS CLI install and setup so that you can interact with AWS service via the CLI on your local machine.
At the time of writing there are two version of the AWS CLI. It is recommended to install version 2 of the software as all the dependencies are built in.
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
A binary will be installed at /usr/local/aws
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
You can test the installation with the aws --version command.
aws --version
# output
aws-cli/2.0.8 Python/3.7.4 Darwin/19.3.0 botocore/2.0.0dev12
You will need to ensure that your user has sufficient permission to manage resources. For my personal account I have applied AdministratorAccess . This could differ for an organisation or yourself depending on how you have AMI permission setup.
In order to interact with AWS via the CLI tools you will need to generate API keys. Generate API keys for you user in the AWS console by navigating to:
The details can be downloaded as a csv or use them in the next step before proceeding.
I prefer to set my keys as environment variables in my shell environment. I am using a zsh shell
# ~/.zshrc
export AWS_ACCESS_KEY_ID="SECRET_KEY_ID"
export AWS_SECRET_ACCESS_KEY="SECRET_KEY"
Ensure that your ~/.zshrc file is only readable by yourself
chmod 0600 ~/.zshrc
Source your ~/.zshrc file to load the variables into your shell environment.
source ~/.zshrc
Now it's time to configure your AWS CLI environment using the aws configure command.
aws configure
# output
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: us-east-1
Default output format [None]: json
A config file is created in the ~/.aws/ directory
# ~/.aws/config
[default]
region = us-east-1
output = json
Now that the AWS CLI is installed and setup for use you can begin using it. The basic command structure is aws <service> [parameters ...].
You can use the built in help to get more info on how to use a service.
aws s3 help
Example sync of files from the local file system to S3.
aws s3 sync <LOCAL_FOLDER>/ s3://<BUCKET_NAME>
Detailed docs can be found here.
The AWS CLI is a nice and handy way to interact with AWS. In some instances its the only way to interact with it. For example files larger the 160GB can only be uploaded to S3 via the CLI.
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-using.html
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html