Launching an Instance and attaching with EBS Volume Using AWS CLI
Let’s learn how to work on AWS using AWS CLI.
Before Start the practical part, I want you to have some little knowledge of the AWS Cloud platform so that you can easily relate its practical part. That’s why I am writing the introduction part of AWS.
Introduction Of AWS
Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. 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. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).
The AWS technology is implemented at server farms throughout the world and maintained by the Amazon subsidiary. Fees are based on a combination of usage (known as a “Pay-as-you-go” model), hardware, operating system, software, or networking features chosen by the subscriber required availability, redundancy, security, and service options. Subscribers can pay for a single virtual AWS computer, a dedicated physical computer, or clusters of either. As part of the subscription agreement, Amazon provides security for subscribers’ systems. AWS operates from many global geographical regions including 6 in North America.
Amazon markets AWS to subscribers as a way of obtaining large scale computing capacity more quickly and cheaply than building an actual physical server farm. All services are billed based on usage, but each service measures usage in varying ways. As of 2017, AWS owns a dominant 33% of all cloud (IaaS, PaaS) while the next two competitors Microsoft and Google have 18%, 9% respectively according to Synergy Group.
Now, We will see the solution to the following problem statements in this article.
- Create a key pair
2. Create a security group
3. Launch an instance using the above created key pair and security group.
4. Create an EBS volume of 1 GB.
5. The final step is to attach the above created EBS volume to the instance created in the previous steps.
Prerequisites: To Perform this task, we will need the following two prerequisites.
- AWS Account
- AWS CLI Application.
We have three ways to do work on the AWS platform i.e WebUI, CLI, and SDK. but here we will use the AWS CLI application, So before starting the practical part. You should know about AWS CLI. that’s why I am writing some introduction part of AWS CLI.
AWS Command Line Interface
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.
How to create an IAM Account through AWS Root Account.
To create an IAM User Account, you should have an AWS Root Account. If you have not. then please follow the AWS documentation to create an AWS Root Account. So Now let’s jump on the creation of an IAM User Account.
Step 1.1: First of all you have to log in with Root AWS Account after then click on “Services”.
Step 1.2: Search “IAM” on the search bar then press the enter key.
Step 1.3: Click on “Users”.
Step 1. 4: Click on “ Add user”.
Step 1.5: Give your User name whatever you want and Select the highlighted Steps. In the last, Click on “ Next: permission”.
Note: Here, I am selecting options according to my requirement but you can also choose as you want.
Step 1.6: Click on “add user to group”.
Step 1.7: Give the name to your group and select the policy name which you want. but here, I am selecting “PowerUserAccess” permission. So that I can perform this task smoothly. After then click on “Create group”.
Step 1.8: Click on “Attach”.
Step 1.9: This part is optional, so I’m not giving any tags but you can give any tags according to your need. After then click on “Next Review”.
Step 1.10: Review your user account and click on “Create user”.
Step 1.11: Now, your IAM account is ready so you can log in with this account using either CLI or WebUI. But I will show you both the methods of login in the next section according to the task’s requirement.
Note: Download yours .csv file. So when you will log in through CLI that time you will need this file.
How to install AWS CLI in your system.
After creating the IAM account, you will need to install the AWS CLI in your system. Here I am using the Linux operating system so I have to AWS CLI for the Linux system But if you are using Windows or Mac operating system then you have to install AWS CLI according to your need. So let’s jump to the installation part of AWS CLI in Linux OS.
Prerequisites for Linux
- You must be able to extract or “unzip” the downloaded package. If your operating system doesn’t have the built-in
unzipcommand, use an equivalent.
- The AWS CLI version 2 uses
less. These are included by default in most major distributions of Linux.
- We support the AWS CLI version 2 on 64-bit versions of recent distributions of CentOS, Fedora, Ubuntu, Amazon Linux 1, and Amazon Linux 2.
- We support the AWS CLI version 2 on Linux ARM.
- Because AWS doesn’t maintain third-party repositories, we can’t guarantee that they contain the latest version of the AWS CLI.
Install the AWS CLI version 2 on Linux.
Step 2.1: Run the below command to download a zip file od AWS CLI
curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o “awscliv2.zip”
Step 2.2: Run the below command to unzip your file.
Step 2.3: Run the below command to install CLI.
Step 2.4: Check AWS CLI is installed or not using the below command.
Now AWS CLI has installed in the system if your system is showing the above output.
How to login with AWS Account through CLI
To perform the above task assigned, we need to configure the IAM — User profile that I have already created earlier. For the first time, we need to run this command. The command is as follows:
Here, we need to add the Access-key and Secret-key provided by AWS while creating this IAM User (see step 11.1). Also, along with this, we need to mention the default output format and the region. Here, the region I am using is Mumbai i.e. ap-south-1.
Now, you have logged in to your IAM Account, and also “aws help” is a command which will help you to find out all commands of aws commands according to your requirement.
Step 3.1: Create a key pair using the below command.
Note: Here, “ mykey” is the key name which will use when you will launch the instance so remember this name and also give this name according to your comfort.
Here, I am showing you that my key pair is created or not. So to show the output, I have to log in with my IAM account that’s why I am showing you how to log in with the IAM account. To log in with IAM Account you will need to AWS Account ID, USER_NAME and PASSWORD. So you have to take the account id from your Root Account and USER_NAME and PASSWORD have to use which you gave during the creation of the IAM Account.
Step 3.2: Copy the Account Id from your Root Account.
Step 3.3: Give your username and password with Account Id.
Now, you have logged in with your IAM Account.
Step 3.4: Click on Services and select EC2.
Step 3.5: Click on the “EC2 Dashboard” and select “key pair”.
Now, you can see the key pair which I created.
Step 3.6: Create a security group using the below command. and write down the security group id because you will need it during the launching of the instance.
Again, I am showing you our security group is created or not. So checking the security you have to open the EC2 dashboard the click on the “security group”.
Output: Now, you can see my created group is existing.
Step 3.7: Launch the instance using the below command.
Output: Here, you can see the all details of your instance. Also, write down the highlighted part because you will need it when you will attach your volume with your instance.
Also, you can check through WebUI that it is existing or not.
Step 3.8: Create the Volume using the below command and write down “VolumeId”.
Output: you can see my volume is ready.
Optional: you can take your instance id through WebUI also.
Step 3.9: Attach the EBS Volume with your instance using the below command.
Output: Now you can check volume has been attached with your instance.
Now, we have attached our EBS volume with an instance. Also, we learned how to create an IAM account and logged in through either CLI or WebUI. Hopefully, you have enjoyed this article.
Thanks for reading this article…