Exploring the useful AWS CLI commands (part 1)….!!!
Hello folks…!!!
Today I’ve come with an interesting topic, about the AWS CLI. We’ll see some of the key commands that are used to create a EC2 instance. We’ll also attach an EBS volume to it, for the extra storage rather than the root one. We’ll see the following key points :
- Create a Key-pair.
- Create a Security group.
- Create & launch an EC2 Instance.
- Create & Attach the EBS volume of 1 GiB to an EC2 instance.
- Stop the EC2 instance.
Here I’m going to use the Window’s 10.
Creating an IAM user :
So very first of all we will see how to make an IAM user. To create an IAM user follow the steps given below :
- Click on the “Add user” in the IAM User dashboard.
2. Give name to the IAM user & set the access type & fill the credentials.
3. Attach the existing policies to the IAM user account. Here we are going to attach the PowerUserAccess policy with the IAM user.
4. Give a tag to the IAM user (Optional).
5. Review the IAM user.
6. After the 5th step click on create user. It’ll create a new IAM user with the specified roles assigned to it. After creating the IAM user, login to the IAM user by using the given login credentials .
Now we will check the version of the AWS CLI which is installed in our OS.
From now onward we will start the main topic of exploring some useful commands of the AWS CLI. For this we will have to first login to the IAM user via command prompt. For this we will use the Access key id & Secret access key.
Create a Key-pair :
For creating a key pair we use the following command :
After putting this command in the AWS CLI we get the following result.
Now we can check in the GUI whether a new key pair through AWS CLI is created or not.
Creating a Security group :
To create a security group we use the following command :
After putting this command on the AWS CLI we get the results like below :
We can also check in the GUI whether the Security group is actually created or not.
Create & launch an EC2 instance by using the above key pair & security group :
For creating an EC2 instance we will need the key pair & security group. So we will use the recently created key pair & security group. It can be done by using the command :
After running this command on the terminal we get the results :
We can also check in the GUI that whether our recently created instance is running or not.
Yes, it working very fine as expected.
Now we will create an EBS volume to give it more external storage just like a Pen drive & we’ll attach it to the EC2 instance that we have just created.
So, let’s get started.
Create an EBS volume of 1 GiB :
To create an EBS volume of the size 1 GiB, we put command :
After putting the command we will get results like below :
On the GUI also we can see that the 1 GiB of volume is created.
Ok, as the EBS volume is successfully created, so now we an mount this EBS volume to the EC2 instance.
Attaching/mounting the EBS volume to the EC2 instance :
By using the following command we can attach/mount our EBS volume of 1 GiB to the EC2 instance.
When we put this command on the AWS CLI with the right parameters it will attach the corresponding EBS volume of 1 GiB to the EC2 instance.
Let’s see in the GUI for confirming whether the EBS volume is mounted or not.
As we can see that the EBS volume of 1 GiB is attached successfully & also the EC2 instance is running well.
Stop the EC2 instance :
for stopping the instance from the AWS CLI we use the following command :
When we put this command in the AWS CLI it gives us the following result :
For confirming that the EC2 instance we have created is really stopped working, we can check it through the GUI.
Here we have completed all the basic commands which are useful in the AWS CLI i.e, from creating an EC2 instance till the stopping the same instance.
Conclusion :
Hence we have successfully completed the part 1 i.e, explored all the helpful but necessary commands of the AWS CLI.
Stay tuned for the next blog. Thank You.