Managing and using EC2 services of AWS cloud using AWS CLI

AWS is a cloud computing platform from Amazon. It’s always beneficial to know how many ways you can connect and run commands to create and manage AWS services.

There are three ways you can connect and manage services on AWS. In this post, we will explore on of the way from that three ways i.e. AWS CLI

AWS CLI

What is AWS CLI ?

The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.

In this post we will see following actions through AWS CLI

  1. To Create a key pair
  2. To Create a security group
  3. How to launch an instance using the above created key pair and security group.
  4. How to attach the above created EBS volume to the instance you created in the previous steps.

Prerequisites

We need to install AWS CLI on your laptop . You can download from link given below:

https://awscli.amazonaws.com/AWSCLIV2.msi
  • Login to aws account through CLI

To login into aws account through CLI we should have access key and secret key .We can get these two keys by adding new IAM user through IAM service of AWS.

  • How to add user on IAM :
  • To add policy of PowerUserAccess to the user

Here we can see the details of the user which we are adding :

After this page at next page you will get Access and secret key :

Now we have both the keys so now we can log in to aws account through cli

  • Let’s see how we can login through CLI to AWS account :

We need to configure our AWS CLI for the user (cli_user_of_aws)which we we created above:

configure AWS CLI for the user
  • Now let’s create key through CLI by using following command
#aws ec2 create-key-pair --key-name <key name>
Creating key pair

now we created key through cli if we will see from webui we can see our created key pair. Which looks like shown in the following picture:

  • I have created security group through cli using following command:
aws ec2 create-security-group --group-name <SG group name> --description <description>

We can also check from WEBUI it is created or not:

  • To add inbound rule with ssh and add the porotocol tcp and ssh works on port num 22
aws ec2 authorize-security-group-ingress  --group-name  <sg name> --protocol <protocol name> --port <port name>  --cidr <source>
  • After above step I launched Instances using above created key pair and security group in the availability zone ap-south-1a (MUMBAI) region

command used to launch is :

#aws ec2 run-instances --image-id    <image id> --instance-type    <type of instance> --count <count of instance> --subnet-id <id of the subnet> --security-group-ids <security group ids> --key-name <name of the key>
Launched instance by using command

checked from WEBUI:

  • Now Let’s see how to create EBS volume of 1 GB using command:
#aws ec2 create-volume --volume-type <volume type> --size <size in gb>  --availability-zone <zone name>

I created EBS volume of 1 gb :

EBS volume created using command

We can check from WEBUI :

  • Now let’s attach created volume to previously launched instance by using following command :
aws ec2 attach-volume --volume-id <id of the volume> --instance-id <instance id> --device <device name>

Volume attached to launched instance and also checked from webui as shown following picture :

volume attached

Now all steps of process which I wanted to do that completed.

(I learned these under the guidance of Mr. Vimal Daga sir.

Thank you sir ! )

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A “Brave” way to brows blocked content from terminal

Let’s end the FastAPI vs Flask debate

Top Online Programming Resources

APIs are Products — and Products Need a Store

Restrictions for declaring a class in java

Azure Data Factory Pipelines For The Win

Quicksort

Making SQL Fun Again with Azure Data Studio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Priyanka Hajare

Priyanka Hajare

More from Medium

Getting Started with AWS S3 Versioning

How to Setup an EC2 Instance on AWS?

How to Setup an EC2 Instance on AWS?

Installing Terraform using AWS Cloud9; Setting up a Docker provider and building an image with…