In this lecture,
we will see how to programmatically interact with the AWS cloud.
Previously, we saw that when we create an IAM user,
there are two access methods that can be provided.
The first one is the access to the management console using a username and a password.
The second method is to access programmatically
by making use of access keys.
The AWS CLI is an open source tool that allows us to interact with AWS services
using command line tools such as Linux Shells,
Command Line Prompts, and PowerShell and Windows.
The current version of the AWS CLI as of this recording is version 2,
and it can be installed on all popular operating systems.
The link in the reference section provides detailed instructions on how to download,
install and configure AWS CLI on the operating system of your choice.
Irrespective of the OS that we choose,
installing the CLI tool is as simple as downloading the required package,
either with the graphical user interface, or the GUI,
or making use of the CLI as shown here.
Once downloaded, we can install the CLI by making use of the install script in Linux,
or by launching the installer
and following the on-screen instructions in other platforms.
Once we have downloaded the AWS CLI, we need to configure it
so that it can connect to our specific AWS account.
This is where the access key ID and the secret access key come in to the picture.
To configure the AWS CLI, run the command "aws configure".
This command when run will prompt for additional information.
The first two inputs to be provided are the Access Key ID and the Secret Access Keys
that were downloaded from the management console for the user.
Next, we need to specify the default region
which should be used when deploying resources in AWS.
Normally, this is set to the region closest to the user,
but it can be set to any other region depending on our preference.
Once a default is set, we can also override it later when using the tool.
We will see how to do that later.
The final input that we have to provide while configuring the AWS tool
is the default output format.
This can be set to a type of JSON, YAML, Text or Table.
Here we have made use of the JSON format as the default.
Once we enter all this information, the CLI is configured,
and we are now ready to use it to manage our AWS environment.
The credentials and configuration that we provided
are stored inside a hidden directory called .aws in the home directory of the user.
Now that we have configured the AWS CLI, let's start using it.
The syntax of using the CLI is like this.
The base command to be used is aws.
This is followed by the top-level command
which is normally the service that we want to interact with.
Following this is the subcommand, which specifies which operations to perform.
All commands come with additional options and parameters
that can be provided to interact with the AWS account.
To illustrate this, let us create an IAM user called lucy using the AWS CLI.
We can do this by running the command “aws iam create-user --user-name lucy”.
Here, the command is IAM, which is the service that we want to make use of.
The subcommand is create-user.
The option called user-name allows us to provide the user that we want to create,
which is lucy in this case.
Once the command is run, the details related to the newly created user
should be displayed on the screen, like this.
Here we can see the username, the creation date, user ID,
and something something called as the ARN.
ARN stands for Amazon Resource Name.
This is a unique name which is assigned to every resource in AWS.
This is done to uniquely identify it with the AWS ecosystem.
Similarly, we can create and manage all other resources using the AWS CLI.
Since there are so many services offered by AWS,
it is impossible to remember every command, subcommand,
options and parameters to use for each of them.
Luckily, we don't have to.
The AWS CLI offers help with all the commands.
To access help, type aws help.
This will open up the comprehensive documentation about how to use the CLI tool
including all the services, commands, and subcommands that can be used.
To get help related to a specific command,
type aws followed by the command name and then help, like this.
In this case, we are looking up help for the iam command.
This will pull up information about the command
and list all the subcommands available to the command.
Finally, to get help related to a particular subcommand or an operation,
such as the create-user in IAM,
use the help command along with the subcommand, like this.
That's it for this lecture.
Let's head over to the hands-on labs and practice working with AWS CLI.