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! 😉
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.
To make sure AWS CLI is correctly set up, run:
which aws
aws --version
The first command prints out the location of install.
The second command checks the CLI itself is working (you should see the cli version printed out).
How easy was that?
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.
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.
Keep these (especially the secret) stored securely. After clicking done you will no longer be able to access the secret key!
Now we have everything we need to configure the AWS CLI. Open your terminal back up and type in the following command:
aws configure
I have already completed the configure step hence it shows my obscured keys. But those doing it for the first time will need to:
Congratulations, you should now be configured to use the AWS CLI 🎉
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:
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.
To exit nano:
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:
Now we have a bucket that is filled with something 😄
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!