Managing and using EC2 services of AWS cloud using AWS CLI
AWS is a cloud computing platform from Amazon. It’s always beneficial to know how many ways you can connect and run commands to create and manage AWS services.
There are three ways you can connect and manage services on AWS. In this post, we will explore on of the way from that three ways i.e. AWS CLI
What is 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.
In this post we will see following actions through AWS CLI
- To Create a key pair
- To Create a security group
- How to launch an instance using the above created key pair and security group.
- How to attach the above created EBS volume to the instance you created in the previous steps.
We need to install AWS CLI on your laptop . You can download from link given below:
- Login to aws account through CLI
To login into aws account through CLI we should have access key and secret key .We can get these two keys by adding new IAM user through IAM service of AWS.
- How to add user on IAM :
- To add policy of PowerUserAccess to the user
Here we can see the details of the user which we are adding :
After this page at next page you will get Access and secret key :
Now we have both the keys so now we can log in to aws account through cli
- Let’s see how we can login through CLI to AWS account :
We need to configure our AWS CLI for the user (cli_user_of_aws)which we we created above:
- Now let’s create key through CLI by using following command
#aws ec2 create-key-pair --key-name <key name>
now we created key through cli if we will see from webui we can see our created key pair. Which looks like shown in the following picture:
- I have created security group through cli using following command:
aws ec2 create-security-group --group-name <SG group name> --description <description>
We can also check from WEBUI it is created or not:
- To add inbound rule with ssh and add the porotocol tcp and ssh works on port num 22
aws ec2 authorize-security-group-ingress --group-name <sg name> --protocol <protocol name> --port <port name> --cidr <source>
- After above step I launched Instances using above created key pair and security group in the availability zone ap-south-1a (MUMBAI) region
command used to launch is :
#aws ec2 run-instances --image-id <image id> --instance-type <type of instance> --count <count of instance> --subnet-id <id of the subnet> --security-group-ids <security group ids> --key-name <name of the key>
checked from WEBUI:
- Now Let’s see how to create EBS volume of 1 GB using command:
#aws ec2 create-volume --volume-type <volume type> --size <size in gb> --availability-zone <zone name>
I created EBS volume of 1 gb :
We can check from WEBUI :
- Now let’s attach created volume to previously launched instance by using following command :
aws ec2 attach-volume --volume-id <id of the volume> --instance-id <instance id> --device <device name>
Volume attached to launched instance and also checked from webui as shown following picture :
Now all steps of process which I wanted to do that completed.
(I learned these under the guidance of Mr. Vimal Daga sir.
Thank you sir ! )