Configuring AWS EC2 Instance Using CLI

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

MishanRG
MishanRG
Oct 18, 2020 · 4 min read

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.

The Startup

Get smarter at building your thing. Join The Startup’s +789K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +789K followers.

MishanRG

Written by

MishanRG

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

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +789K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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