![Graphic with post title: AWS CLI Tutorial - How to Install, Configure and Use AWS CLI.](https://static.wixstatic.com/media/05283e_612d91fd89af42549ef86adca024f715~mv2.png/v1/fill/w_49,h_49,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_612d91fd89af42549ef86adca024f715~mv2.png)
Install
Installing the AWS CLI is dead easy. Your best bet is heading over to this AWS webpage which gives you detailed instructions on how to get started for each operating system.
But, if you're on a Mac 💻 like me then stay here! 😉
Step 1: Copy and paste the following into your terminal:
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
What does this do? Well the first command uses the curl command line tool to download the AWS CLI package from AWS.
The second command then installs the AWS CLI package using the built in Mac installer.
Step 2: Check installation was successful:
To make sure AWS CLI is correctly set up in your $PATH, run the "which aws" command to print out the location of install.
Now run "aws --version" to check the CLI itself is working (you should see the cli version printed out).
which aws
aws --version
![macOS terminal screenshot checking successful aws cli installation](https://static.wixstatic.com/media/05283e_8a043a8b5ece45618e3eb60d1ac9716f~mv2.png/v1/fill/w_49,h_35,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_8a043a8b5ece45618e3eb60d1ac9716f~mv2.png)
How easy was that?
Configuration
Head over to the AWS console, sign in and complete the following steps. If you haven't already made an AWS account check out this CourseWizz tutorial.
Step 1: Click on the Account name dropdown.
![AWS Console screenshot to click on account in top right corner.](https://static.wixstatic.com/media/05283e_6aabce52e85c4ec3a865cb8caa7af6e9~mv2.png/v1/fill/w_49,h_27,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_6aabce52e85c4ec3a865cb8caa7af6e9~mv2.png)
Step 2: Click on Security and Credentials
![AWS Console screenshot showing to click on Security credentials in the account dropdown.](https://static.wixstatic.com/media/05283e_3c15e5d3038345dfa311632e029ce496~mv2.png/v1/fill/w_49,h_27,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_3c15e5d3038345dfa311632e029ce496~mv2.png)
Step 3: Click on Create Access Key button:
This will create a root user Access Key. In practice you should create IAM roles and assign least privileged permissions and generate keys for each role.
![AWS Console screenshot showing to click on the Create access key button.](https://static.wixstatic.com/media/05283e_549420cd45074276a3b4f90dfc90f3c5~mv2.png/v1/fill/w_49,h_27,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_549420cd45074276a3b4f90dfc90f3c5~mv2.png)
Step 4: Confirm you are happy to create key and click Create access key button
![AWS Console screenshot showing to click on Create access key button, after clicking checkbox.](https://static.wixstatic.com/media/05283e_e59e5c7f60994acd8d8eafa35b4cde57~mv2.png/v1/fill/w_49,h_27,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_e59e5c7f60994acd8d8eafa35b4cde57~mv2.png)
Step 5: Success, you now have both Access Key and Secret Access Key:
Keep these (especially the secret) stored securely. After clicking done you will no longer be able to access the secret key!
![AWS Console screenshot of Access Key created page which reveals both Access and Secret Keys.](https://static.wixstatic.com/media/05283e_c3e6865f05ba4ccba001d47849580389~mv2.png/v1/fill/w_49,h_27,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_c3e6865f05ba4ccba001d47849580389~mv2.png)
Back to the Terminal
Now we have everything we need to configure the AWS CLI. Open your terminal back up and type in the following command:
aws configure
![macOS terminal screenshot where user has entered aws configure and has filled out details.](https://static.wixstatic.com/media/05283e_70af9a51a032414b81e0d993755e9cfc~mv2.png/v1/fill/w_49,h_31,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_70af9a51a032414b81e0d993755e9cfc~mv2.png)
I have already completed the configure step hence it shows my obscured keys. But those doing it for the first time will need to:
1) Copy and Paste Access Key
2) Copy and Paste Secret Access Key
3) Specify default AWS region
4) Specify default output format. I choose json as it's my preferred although there are other options like standard text and yaml
Congratulations, you should now be configured to use the AWS CLI 🎉
Use
So what can i do with the newly installed AWS CLI?
You can do pretty much everything that can be done in the online AWS Console. But now, instead of opening up your browser and signing in, you can open the terminal and get straight to it.
Let's do something with it...
We will start simple, let's create a private S3 bucket called coursewizztestbucket and we are going to upload a something.txt file to it.
Type the following into the cli:
aws s3api create-bucket
--bucket coursewizztestbucket
--region eu-west-2
--create-bucket-configuration LocationConstraint=eu-west-2
This command tells AWS CLI to use the create-bucket function of the S3 api. Additional options can be provided, options are denoted by -- and the following string is the value.
In this example we included --bucket --region --create-bucket-configuration. These are the minimum required options to create an S3 bucket.
If your bucket has been successfully created you will expect to see a JSON object with the location property printed:
![macOS terminal screenshot showing successful creation of S3 bucket.](https://static.wixstatic.com/media/05283e_48c8d224f0fc4ae98498e5fb16bf9902~mv2.png/v1/fill/w_49,h_30,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_48c8d224f0fc4ae98498e5fb16bf9902~mv2.png)
Great now we've made a bucket!
It looks quite empty, shall we put something inside?
Create a text file called "something.txt" and open the editor in the terminal.
touch something.txt
nano something.txt
"touch something.txt" creates a new file called something.txt.
"nano something.txt" opens nano, which is a terminal based editor. Now we can write something.
![macOS terminal screenshot of nano editor in something.txt.](https://static.wixstatic.com/media/05283e_4e2649d5514a4d85b398ddf0175d73fd~mv2.png/v1/fill/w_49,h_30,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_4e2649d5514a4d85b398ddf0175d73fd~mv2.png)
To exit nano:
Press Ctrl x which will ask if you want to keep file changes. Press y for yes.
Now you will be asked what filename you want to write to, it should be pre-filled with something.txt, so press enter.
![macOS terminal screenshot of nano editor saving file changes.](https://static.wixstatic.com/media/05283e_5c4b8c319cd348c5b5959babd2969948~mv2.png/v1/fill/w_49,h_30,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_5c4b8c319cd348c5b5959babd2969948~mv2.png)
![macOS terminal screenshot of nano editor saving file.](https://static.wixstatic.com/media/05283e_97d5a68aa0d84645b5e22cd7024d74d7~mv2.png/v1/fill/w_49,h_30,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_97d5a68aa0d84645b5e22cd7024d74d7~mv2.png)
Now we want to upload something.txt to our newly created S3 bucket.
Lets enter the following command:
aws s3api put-object
--bucket coursewizztestbucket
--body something.txt
--key something
This time we are using put-object of the S3 api which uses a HTTP PUT request to upload a blob (our file something.txt) to S3. The options passed are bucket (specifies the bucket), body (file we are uploading) and key (unique name or id for the object in S3). See here for the full documentation of put-object.
If the upload was successful you should expect to see a JSON response with ETag and ServerSideEncryption properties printed like so:
![macOS terminal screenshot of successful put-object upload to S3.](https://static.wixstatic.com/media/05283e_ae14c5e28ed24b6ab9ca80f8f6710cd8~mv2.png/v1/fill/w_49,h_29,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/05283e_ae14c5e28ed24b6ab9ca80f8f6710cd8~mv2.png)
Now we have a bucket that is filled with something 😄
Summary
As you can see using the AWS CLI is nice, fast and easy! With some practice, you'll master the AWS APIs, allowing you to swiftly launch instances, upload files to S3, or handle any other task with ease.
For comprehensive AWS CLI guidance, refer to the AWS User Guide - especially if you're not yet an expert!