Installing, configuring and using the AWS CLI.
If you are an AWS user then you might be aware that there is pretty much an API for every AWS service out there.
Some clever python developers took boto3 and created the AWS-CLI and aws-shell (which is almost like the cli, but with autocomplete etc).
TL;dr , you can use the aws-cli to do many mundane tasks that would have taken a long time to complete in the web console, by using the CLI you can quickly
do many different things in almost no time.
Before we get to the technical parts, let's get something straight. AWS stands for "Amazon Web Services" and my interpretation of "Amazon Web Services" is that
AWS built a bunch of servies and each of these services has a REST API that you can use to interact with the service. If you have a REST API, then it is really
easy to write code to interact with the REST API in almost any programming language. That is why you will see there are so many libraries in different programming
languages for interacting with AWS. The aws-shell and aws-cli are just abstractions built on top of the boto3 library(which just interacts with the REST API's of
several AWS services.) I think the basic idea here is that you can control infrastructure with a REST API and essentially with code. This is a really cool idea
compared to setting up rack servers and network switches and aircon setups yourself, the only trade off is that most cloud providers are extremely expensive.
So please take note that an important part of learning how to use Cloud services is learning how to use Cloud services in a cost effective manner.
Let's start by installing everything that you need. I am assuming you are either on a Mac or on a mainstream Linux distro such as Ubuntu.
Just to set somethign straight the aws-cli is what most people use and github project can be found here:
https://github.com/aws/aws-cli
The aws-shell is basically a nice version of the aws-cli with fancy added features like autocomplete etc and the github project for that is found here: https://github.com/awslabs/aws-shell
You can start by installing then aws-shell. You can either do it in a virtualenv, which would probably be a good idea, but that would restrict your use of the aws-shell command to the virtualenv only instead of allowing you to use it globally. To install it globally run the following:
$ sudo pip install aws-shell --upgrade --ignore-installed six
You can either manually configure the aws-shell or you can do it automatically. These are the important configuration files for the aws-shell:
(I'm just using cat command to show what the output would be of the file, obviously I'm not gonna show the contents of my file)
This file can be found at $HOME/.aws/credentials. This is where you store
$ cat ~/.aws/credentials
This is what the output might look like:
[default]
aws_access_key_id = <LEFT BLANK COZ DUH>
aws_secret_access_key = <LEFT BLANK COZ DUH SECRETS>
[MYEC2USER]
aws_access_key_id = <LEFT BLANK COZ DUH>
aws_secret_access_key = <LEFT BLANK COZ DUH SECRETS>
The other important file is found at $HOME/.aws/config
$ cat ~/.aws/config
This is what the possible output would look like:
[default]
output = table
region = ap-southeast-1
As you can see this file specifies the default region to use when interacting with AWS, it also specifies the output type
for the aws-cli. There are various output types: json,csv,table etc.
So what is an example of something actually useful that you could do with the aws-cli?
I'm actually not going to get into that, you can have a look over these tutorials that cover the topic really well:
http://blog.ruanbekker.com/blog/2017/08/28/change-iam-username-with-aws-cli/
http://blog.ruanbekker.com/blog/2017/09/22/using-the-aws-cli-tools-to-grab-cloudwatch-metrics-for-elasticsearch/
https://sysadmins.co.za/your-first-python-lambda-function-on-aws-using-the-aws-cli-tools/
Btw if you were wondering, I'm not Ruan. I know that isn't very convincing. Lol
Something important to take note of is that if you have the aws-cli installed and configured then you don't need to hard code credentials when doing
coding projects with for example the AWS java client or boto3, the code should detect that you have credentials in ~/.aws/credentials if no creds are hardcoded
in your code. Just take note for some services you might need to specify the endpoint that will be used, you can find all the possible endpoints here: