Hello Everyone ,
In this blog, I am going to explain that how we can operate on AWS cloud through AWS CLI Program. Before that we need to know some concepts that we are going to use in this blog , that are :
What is AWS CLI Program ?
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. By this way we can operate on AWS Services remotely. To use AWS CLI , we need to install it and then we will configure it. To use the AWS account we need to have IAM user credentials for the authentication.
What is IAM User ?
AWS Identity and Access Management (IAM) enables us to manage access to AWS services and resources securely. Using IAM, we can create and manage AWS users and groups, and use permissions to allow and deny their access to AWS resources. IAM is a feature of our AWS account offered at no additional charge. When we create the IAM user then we get the Access key and the Secret key as the login credentials.
What is Key pair?
A key pair is a combination of a public key that is used to encrypt data and a private key that is used to decrypt data.
What is security group?
A security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance.
First of all, lets create the IAM user. We will create the IAM user with step by step on the AWS Cloud console :
Now we will create a new user by clicking on the Add user button.
Hence, we have successfully created the user . It will provide the Access key and the secret key as the login credentials from AWS CLI. I will download this csv file or we can say the credentials csv file.
Now, lets configure the AWS CLI with these Access key and Secret keys in order to connect to the AWS account using the command : “aws configure”
As we have configured it without any error , lets see that it is connected or not ?
We will fetch the ec2 instances details using aws CLI commands i.e.,
“aws ec2 describe-instances”
It provided all the details in the default JSON format. Also these are the details of the instances that are already there in my AWS account.
Agenda Description that we wants to perform
My plan is to create
- Key Pair
- Security group
- EC2 instance with above created key Pair and security group
- EBS volume
- Attach the EBS volume with the above created EC2 instance.
Lets start with creating Key pair , we use the command :
“aws ec2 create-key-pair”
This generated private key will be stored in a file named MyKey110.pem(in my case).
Now, we will create the security group :
Since this security group doesn’t have any firewall rules , so it won’t allow any traffic to come in. For this we need to add the ingress rule to it, i.e.,
Here we come to the Instance launching step , we are going to use the this key pair and security group.
Its good practice to add tags for the instance that we have created. Create the tags using the instance in which we need to add the tags.
Hence, we have successfully created the EC2 instance . Now lets create the EBS volume of type gp2 and size 1 GB , in the same availability zone where we have launched our EC2 instance. (Reason : Because EC2 is a regional service and it only allow the volumes of same availability zone to be attached).
Lets attach this volume to the EC2 instance to be used for the storage.
Hence we have done all the task successfully .After following all the steps , you can check your AWS cloud Dashboard to look for the instance that is being created or not. Also , we can check from the CLI just like we did in the initial step.
Since our work and experiment is done So its a good practice to terminate the instance, so that AWS won’t charge us. For terminating the instance , we use the command “aws ec2 terminate-instances”
Hence we have terminated the EC2 instance successfully.
Yeah!!!! we are done with our Agenda . Hope you like this blog. Feel free to ask any query , also all the suggestions are really acceptable and appreciated.
Thank You !!!