Configuring AWS EC2 Instance Using CLI

How to install AWS CLI and launch an EC2 instance and attach an EBS Volume to it.

MishanRG
The Startup
Published in
4 min readOct 18, 2020

--

AWS is a public cloud service provider that provides on-demand cloud computing platforms and APIs to individuals, companies, and governments on a metered pay-as-you-go basis.

AWS has a huge range of services which the user can use according to their need. AWS services can be used or accessed using

a) AWS Console: The AWS Management Console brings the unmatched breadth and depth of AWS right to your computer or mobile phone with a secure, easy-to-access, web-based portal.

b) 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.

c) AWS SDK’s: It is a collection of software tools to create applications and libraries that use Amazon Web Services (AWS) resources. There are separate software development kits (SDKs) for browser-based or server-side application development.

In this blog, I will be explaining how we can configure an EC2 instance(one of the computing services of AWS) using AWS CLI. Let’s get started…

Step 1:

When we log in as a user in the Web UI Console, we provide our ID and password for login. As we are using a CLI, some programs access the AWS, so to authenticate that it is the right user using that program, we need an access key and secret access key for our program to access AWS Cloud.

We create a new IAM user and give that user access to AWS CLI and AWS Console(for our demo).

Step 2:

Download aws CLI software in your system and configure it with the account created above.

Step 3:

We will create a private key that can be used to access our instance and do this before creating the instance.

We get the key downloaded in the path where we used this command.

Step 4:

We now create a security group using the CLI. We do that, as shown in the below screenshot.

We have to set the inbound traffic in the security group. We set the traffic using the command, and we set the inbound traffic for all IP and allow all port to access :

We can see our security group in the below image, which we create using the AWS CLI.

Step 5:

Now we launch our EC2 instance with the above created Key-Value Pair and the Security Group. We will configure our instance using the CLI command as well.

We can use the command:

aws ec2 run-instances — security-group-ids group_id — instance-type _type_ — image-id ami_id — key-name key_name — count no_of_instance

Now we have created an instance using AWS CLI, and we can check that into our Dashboard also.

Step 6:

Now we are going to attach an EBS volume to our instance using CLI. And we can use the command:

aws ec2 create-volume — volume-type volume_type — size volume_size — availability-zone AZ_name

And now, to attach this volume to our instance, we can do it as below:

NOTE: The EBS volume should be launched in the same availability zone where our EC2 instances are launched; otherwise, we cannot use it because EBS is a zonal service.

Step 7:

Now we will check from the Dashboard that we have done everything right or wrong. We can see two-volume in the below image, which means that we have one volume from the instance, i.e., 10 GB, and another volume from EBS, i.e., 1GB.

Conclusion

Finally, we can conclude our work here, and we have successfully launched an EC2 instance using CLI and have successfully attached an EBS volume to that instance.

Thank you for reading the blog, and please do suggest to me some ideas for improvement. Your suggestions will really motivate me.

--

--

MishanRG
The Startup

I blog about ML, Big Data, Cloud Computing. And improving to be the best.