top of page

AWS CLI Tutorial – How to Install, Configure and Use AWS CLI

Updated: Sep 20, 2023


Graphic with post title: AWS CLI Tutorial - How to Install, Configure and Use AWS CLI.

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

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.

Step 2: Click on Security and Credentials

AWS Console screenshot showing to click on Security credentials in the account dropdown.

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.

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.

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.

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.

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.

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.

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.
macOS terminal screenshot of nano editor saving file.

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.

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!


Frequently Asked Questions

What is the AWS CLI?

Why should I use the AWS CLI over the AWS Management Console?

How do I update the AWS CLI?

Is the AWS CLI free to use?

Can I use AWS CLI on any operating system?

How do I troubleshoot issues with the AWS CLI?

Is there a way to autocomplete commands in AWS CLI?

How secure is it to use AWS CLI?

Can I use AWS CLI in conjunction with AWS SDKs?

Where can I find more advanced AWS CLI tutorials?


7 views0 comments
bottom of page