Module 1 - Activity 1 - Install and Configure The AWS CLI
Module 1 - Activity 1 - Install and Configure The AWS CLI
Activity overview
The AWS Command Line Interface (AWS CLI) is a command line tool that provides an
interface for interacting with products and services from Amazon Web Services (AWS).
Often, people install the AWS CLI directly on their laptop machines. However, in this course
—to ensure that all students have the same setup—you will practice using the AWS CLI
from an Amazon Elastic Compute Cloud (Amazon EC2) instance.
While some instance types have the AWS CLI pre-installed on them (such as Amazon Linux
instances), it is important to know how to install and configure this tool. Therefore, in this
activity, you will practice installing the AWS CLI. A Red Hat Linux instance—that does not
have the AWS CLI installed on it—is provided for you on Amazon EC2.
You will establish a Secure Shell (SSH) connection to the instance. Then, you will configure
the installation with an access key that can connect to an AWS account. Finally, you will
practice using the AWS CLI to interact with AWS Identity Access and Management (IAM).
This diagram summarizes the activities you will complete in this activity.
Activity objectives
After completing this activity, you will be able to:
During this activity, you will take on the role of Sophie. You will install the AWS CLI,
configure it, and practice using the AWS CLI to query details about the IAM service.
5. Read through the three bullet points in this step before you start to complete the
actions, because you will not be able see these instructions when the Details panel is
open.
○ Choose the Details drop down menu above these instructions you are
currently reading, and then choose Show. A Credentials window will open.
○ Choose the Download PPK button and save the labsuser.ppk file. Typically
your browser will save it to the Downloads directory.
○ Then exit the Details panel by choosing the X.
6. Download needed software.
○ You will use PuTTY to SSH to Amazon EC2 instances. If you do not have
PuTTY installed on your computer, download it here.
7. Open putty.exe
8. Configure PuTTY to not timeout:
○ Choose Connection
○ Set Seconds between keepalives to 30
9. This allows you to keep the PuTTY session open for a longer period of time.
10. Configure your PuTTY session:
○ Choose Session
○ Host Name (or IP address): Paste the Public DNS or IPv4 address of the
Bastion Host instance that you noted earlier.
○ Back in PuTTY, in the Connection list, expand SSH
○ Choose Auth and expand Credentials
○ Under Private key file for authentication: Choose Browse
○ Browse to the labsuser.ppk file that you downloaded, select it, and choose
Open
○ Choose Open again
10. To trust and connect to the host, choose Accept.
11. When prompted login as, enter: ec2-user
This will connect you to the EC2 instance.
12. Windows Users: Choose here to skip ahead to the next task.
13. Read through the three bullet points in this step before you start to complete the
actions, because you will not be able see these instructions when the Details panel is
open.
○ Choose the Details drop down menu above these instructions you are
currently reading, and then choose Show. A Credentials window will open.
○ Choose the Download PEM button and save the labsuser.pem file.
○ Then exit the Details panel by choosing the X.
14. Open a terminal window, and change directory cd to the directory where the
labsuser.pem file was downloaded.
For example, run this command, if it was saved to your Downloads directory:
15. cd ~/Downloads
16. Change the permissions on the key to be read only, by running this command:
17. chmod 400 labsuser.pem
18. Return to the AWS Management Console, and in the EC2 service, choose
Instances. Check the box next to the instance you want to connect to.
19. In the Description tab, copy the IPv4 Public IP value.
20. Return to the terminal window and run this command (replace <public-ip> with the
actual public IP address you copied):
21. ssh -i labsuser.pem ec2-user@<public-ip>
22. Type yes when prompted to allow a first connection to this remote SSH server.
Because you are using a key pair for authentication, you will not be prompted for a
password.
For all steps that are in this section: Complete these steps in the terminal window where you
have an active SSH connection to the Red Hat Linux instance running on Amazon EC2.
23. Verify that AWS CLI is now working by running the following command:
aws help
The help command should display the help information for AWS CLI.
aws configure
31. In the terminal window, test the IAM configuration by running this command:
32. If the test is successful, you should see a JSON structured response that shows a list
of all the IAM users in the account. The result should match what you saw in the
AWS Management Console earlier in this activity.
33. Open the AWS CLI Command Reference documentation page for the iam
command.
34. Scroll down to the list of Available Commands.
Activity 1 challenge
Use the AWS CLI Command Reference documentation to figure out how you can use the
AWS CLI to download the lab_policy JSON-formatted IAM policy document. You saw this
policy document in the AWS Management Console earlier in this activity.
Avoid the temptation to use the AWS Management Console. See if you can do this
challenge by using only the AWS CLI.
It might take some experimentation to figure out this challenge because the solution is not a
simple single command. Have patience, and work with other classmates if it helps!
● Tip #1: In the AWS CLI Command Reference documentation page, choose the
hyperlink of any command you might want to use. You can see what information the
command will return, and also see details on how to use the command.|
● Tip #2: Try using the list-policies command. Set a scope to help filter the
results.|
● Tip #3: You will need to run more than one command to successfully complete this
challenge. Some of the output from one command might be required in order to
successfully run the next command. For example, you need to know the lab_policy's
Arn before you can successfully run the get-policy command.|
● Tip #4: Before you can get the actual JSON representation of the IAM policy to
display, you will need to know the policy version. Return to the list of available
commands in the documentation to see if any of them look like they might return a
policy document.|
● Tip #5: Do not forget that you can pipe any terminal output to a new file, by using the
> command. This could be useful for creating the lab_policy.json file you will turn in
at the end of this challenge.|
Activity summary
You successfully installed the AWS CLI on a machine and connected it to an AWS account.
You then practiced using the AWS CLI and referencing the AWS CLI Command Reference
documentation to look up useful command details.
Key takeaways:
● Anything that you can do in the AWS Management Console can also be done
through the AWS CLI.
● You would typically provide a user name and password to connect to the AWS
Management Console, but you needed an access key ID and secret access key to
connect to the same account using the AWS CLI.
In later activities in this course, you will continue to use the AWS CLI.
Tip: If you want to use an AWS CLI installation to connect to a different AWS account, run
the aws configure command again, and provide the new credentials.
Lab Complete
34. Choose End Lab at the top of this page and then choose Yes to confirm that you
want to end the lab.
A panel will appear, indicating that "DELETE has been initiated... You may close this
message box now."
35. Choose the X in the top right corner to close the panel.