Working on Amazon Web services: Using CLI.

AWS (Amazon Web Services) is a comprehensive, evolving cloud computing platform provided by Amazon. Amazon Web Services offers reliable, scalable, and inexpensive cloud computing services. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet.

command-line interface (CLI) processes command to a computer program in the form of lines of text. Operating systems implement a command-line interface in a shell for interactive access to operating system functions or services. Programs with command-line interfaces are generally easier to automate via scripting. Today many programs uses graphical interface for user interaction and ease of use. Amazon Web Service also provide such graphical interface in the form of webUI.

However usage of webUI lacks the ability to automate the usage of service. So to overcome this AWS also provides it’s user with CLI program. Which combined with the ability of scripting helps the user to automate the services.

Task Description:
🔅 Create a key pair
🔅 Create a security group
🔅 Launch an instance using the above created key pair and security group.
🔅 Create an EBS volume of 1 GB.
🔅 The final step is to attach the above created EBS volume to the instance you created in the previous steps.

So let’s do it…

Before we can perform this task we should first look at the prerequisites to perform the task. To use the Command Line Interface of AWS we would first have to download and install the CLI program for AWS, this can be done by a simple Google search - Install AWS CLI and clicking on the first link that comes up and then clicking on the download link, this would download the CLI program provided by AWS. Now simply install the downloaded software, once it has been successfully installed you can check if the installation was successful by using the command:

aws - - version

If this command successfully prints the version of the program, then we can be sure that the program was installed successfully. The second prerequisite to use the program is to create an IAM user account and while selecting the AWS Access Type particularly selecting the Programmatic Access. Doing this would create an account which is capable of using CLI program. This user provides the user Access Key and Secret Key which can be copied in a secure location. Now you can use this account to run CLI. To do so run the command:

aws configure

Where the program will ask you to input:

  1. AWS Access Key ID: Here you can copy the access key provided by aws and press enter.
  2. AWS Secret Key: Here you again can copy the secret key provided by aws and again press enter.
  3. Default Region Name: Here you can type the required AZ’s ID ( for example: ap-south-1a) and again press enter.
  4. Default output format: for now this field can be left empty… again press enter.

Doing this will configure the program and login to the AMI user account you created.

Now that all the prerequisites are completed we can continue with our task.

  1. Creating a Key pair using CLI :

this command creates a key pair with name cli-key and stores it in a file named cli-key with .pem as it’s format on top of the desktop itself.

2. Create a Security Group using CLI :

this command will create a Security Group named cli-sg with the description “security group created using cli”. As the security group has been created successfully, the command returns the GroupID.

3. Launch an instance using the above created key pair and security group via CLI :

through this command we are able to create a new EC2 instance in default AZ (here that being ap-south-1a) with Amazon’s Linux, Instance type t2 micro and with the Key pair and Security group that we just created i.e. cli-key and cli-sg respectively. Now here the instance is in pending mode but we can wait for a while and then go check our EC2 dashboard to see if the instance was launched successfully.

Here we can see that the instance has been launched successfully and is even in running state.

Also we can see through the last image and see that the instance is using the key pair named cli-key the one we created using CLI.

Note: for the last step of the task we can copy the Instance ID from here.

This image also shows that the instance we created is also using the security group cli-sg the SG we created using CLI.

4. Create an EBS volume of 1GB using CLI :

Using the above shown command we can create a EBS volume of size 1GB in the AZ ap-south-1a. Since the volume has been created successfully the command returns the information about the volume as seen above.

We can again go to the WebUI in EBS dashboard to see if the volume was created successfully.

As we can see a new volume of size 1GB was created in ap-south-1a, and is shown as available. We specifically created the volume in ap-south-1a so that we attach the volume to our new instance.

5. Attach the above created volume with the instance we just created using CLI :

While attaching the volume to our Instance using the above command we are required to give the volume ID which can be copied from the EBS dashboard, the instance ID which again can be copied from the webUI from EC2 dashboard and finally the name of the device you want to attach the volume using (here - sdb).

Here we can see that the volume was attached to our instance (check Attachment Information field).

So that’s it… Task done successfully!!!✔

Thankyou for reading. Seeya!!! 😊