Launch Amazon AWS Instance Using AWS CLI
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNx7nBXE5G_kJUWfR8GU_HE6nQLCZEtUbzij5NF7Mt2UQ13sOweX9g9wl_jeEdpaoGfjsP-9H8wGJICQW3RiyHwFIYB8tdVcbAYTeCgSkrUfzZUMivEak2wcC0YSymI1fNKqvgRkpKtZU/s16000/ezgif.com-gif-maker.gif)
Task Objective:-
Statement: From the given Requirement Launch an EC2 instance from Windows Command Prompt.
Requirement :
🔅 Create a key pair.
🔅 Create a security group.
🔅 Launch an instance using the above-created key pair and security group.
🔅 Create an EBS volume of 1 GB.
🔅 The final step is to attach the above created EBS volume to the instance you created in the previous steps.
What is Key-Pair?
A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances. Anyone who possesses your private keys can connect to your instances, so it’s important that you store your private keys in a secure place.
What is the 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. If you don’t specify a security group, Amazon EC2 uses the default security group.
What is the EC2 Instance?
An instance is a virtual server in the AWS cloud. With Amazon EC2, you can set up and configure the operating system and applications that run on your instance.
What is the EBS Volume?
Amazon Elastic Block Store provides raw block-level storage that can be attached to Amazon EC2 instances and is used by Amazon Relational Database Service. Amazon EBS provides a range of options for storage performance and cost.
Let’s Get Started
To Perform this practical you need the AWS CLI package and after install gives that path to the Environment variables in the system.
Install the software from this link:
https://awscli.amazonaws.com/AWSCLIV2.msi
Step 1. Get your AWS login credential or create IAM users and take that user's credentials to log in to AWS Account from CMD.
Type the following command to enter your credentials.
aws configure
I have already entered so it showing like this otherwise you have to fill there.
![](https://miro.medium.com/max/986/1*BJJUym4RFvwQe5G1jwab2Q.png)
Step 2. According to the requirement, we need to create key Pair
To Cerate Key pair we need to type Following Command.
This command has some arguments so the following are the arguments :
-- key-name “any key name”
aws ec2 create-key-pair -- key-name “KEY_Name”
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7z0JBI2MZ_20Zo7UlRckpRg0QFFHk70KniN97h6b8MQ2vdVJr7ODrSMiSSBmDAT1Oj1f0nssOkpDZfDoOY1jg7cQy8Px52_f0HIANgeo_d-qIMuI7DpOp3qRgdbB-tGCNAOhFWrL4ypI/w640-h250/1_C4GE4Is-t4esF9i3yMFYaw.jpg)
Step 3. According to the second requirement, we need to create a security group.
To Create a Security Group we need to type Following Command.
This command has some arguments so the following are the arguments :
-- description “small description about SG”
-- group-name “any name to SG”
-- vpc-id “your vpc id”
aws ec2 create-security-group -- description “little description” -- group-name “any name” --vpc-id “your VPC id”
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihyphenhyphenZ6nZDGJotMTvLTEpySfBE9v5AAquwG6kAAXFvkSx7o1QyYoYJW3h5fUHDSnUd44kqPy6miP3l7V2ouxXumhuAip0JyxfoDkGJGTpulaNObUvI_ATzLBFyBKTAu7zix6dg2NX9n-cGc/w640-h76/1_dGghk6Kwr-7w0Wt7CmJLug.jpg)
Now we have to set some protocols so specific users can connect instances through SSH.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLCo8ePtKZIc1Qf0s4FLYfXoRkATnymxH66WKCSz0WwGTmEpBNmvO8WmDx_FWL6RPLdzOlSabcr6Wp2ZpgHYPbWmmb1MYypWUOzJehwyog-Q-PXZzqpzAW61jFCiiJ-1mYjIxYa34y6cI/w640-h40/1_mZBuLZLiriZou1Ea8B6PTA.jpg)
you can see we have allowed all the traffic from all IPs from port 22 so anyone can connect to instance you can give specific IP to allow as well.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7yuThdYPHaqI6RUzOg-4doR1zbqmeQ3Hf1DHZ3X-L6wb-B3pba7LJE62z1W2VOUoXiHmN2RF5FOg7_Ilf65Q1_g74zAvcM0BaOmYfAOSxCk_Q665o1Sp0eSCwYbLu2Dd-tXigPYRzqfk/w640-h248/1_9TN8k2MnJs38zPC-AvOQuQ.jpg)
Step 4. Now Launch an instance using the above created key pair and security group.
To Launch an instance we need to type Following Command.
This command has some arguments so the following are the arguments :
--image-id “Image id get it from UI”
--instance-type “any flavor of instance Ex. t2.micro”
--key-name “your Key Name”
-- security-group-ids “ security group id”
--subnet-id “your subnet id”
-- count “number of instances”
aws ec2 run-instances -- image-id “Image id get it from UI” -- instance-type “any flavor of instance Ex. t2.micro” -- key-name “your Key Name” -- security-group-ids “security group id” -- subnet-id “your subnet id” -- count “number of instances”
The state showing as “Pending”.
Now the state changed to “Running”.
Step 5. Now we need to Create one EBS Volume to attach as an extra volume to the above-launched instance.
To Create a volume we need to type Following Command.
This command has some arguments so the following are the arguments :
-- availability-zone “your AZ”
-- volume-type “volume type Ex. gp2”
-- size “size Ex. 1gb,2GB”
--tag-specification ResourceType “resource type”,Tags=[{Key=name,value=”Volume name any”}]
aws ec2 create-volume --availability-zone “ap-south-1a” -- volume-type “gp2” --size 1 --tag-specifications ResourceType=”volume”,Tags=[{Key=name,Value=CMD_Volume}]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipR3zttW4MwtjgAUDSW3IYmG3P7iZ2vv0Oa0koajs8mY8vqgbGvQd8IWjyqTHoN9FagjghXeCBobPV1-d_224bC3gBnJYzfGa-0EF0Pxl3_tktJO8a5-ZUmCVsdFZ7D2j1UYKiQMsNH_M/w640-h196/1_HaJWUOlHz4GytUfJ5XlJ9w.png)
Step 6. The final step is to attach the above created EBS volume to the instance you created in the previous steps.
To attach a volume to an instance we need to type Following Command.
This command has some arguments so the following are the arguments :
-- instance-id “your instance id”
-- volume-id “your volume id”
-- device “/dev/device name Ex. sdh”
aws ec2 attach-volume -- instance-id “your instance id” -- volume-id “your volume id” -- device “/dev/device name Ex. sdh”
The State is “Attaching”.
Now the status is “ok” which means we have successfully attached.
Now live screenshots of Web UI.
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcyPJmb5nzFc9-v4A6uJFIGIs1dBLLeGeGawWGwoVp7fXwHCjaJO4hjWxLCt1VFV74VjHAonj3XKw_PbFGftOe4-QB2csFbrphUvQ812EPZirNa5WI4JIgI_KlCPrt4p6Mpf4pxDLzqco/w640-h230/1_FcnPbsy1Jum_LYjshu44cQ.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWr7U-fqrgaJyk26TxkIRstfOBAY0dFgScrI-zSQclHLg5pKJt56sLj9n1CYcQEknoLKsqZHitSisabVdHexegAycjeL3T70Ql80KBBuRsC24fIVG3dPJSHa213onDw5-soSNDSNM3B_Y/w640-h256/1_IIsH_Ily99wYCEXdplqecA.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd07g8Ic5W-hs6NA2KAHvlSyg3Y2OROFlIWhJ0BWam5_W2VYDTM0EAOMgOlX3Kn1Igajn_9iwhVVxL7U-KWCl40Idy6XDlEWjNhfxwwFJRBdp1tY1Mz8B_mEhcbGJJMazHDlCKttprWxs/w640-h294/1_SX04kVedLl5RQ6-DLU-cdg.jpg)
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfnFxcSw102nOvLlWf7YhXSzSqlw9KPK-9bFScleEHeMEfXCSQWpEc96AN7Q4eQU_bJ4zlBRrvnCbeURTsVsKZGj8P21Omn9u4M5oRiOrne9yaLBnxe0F9u9U_qZ90bqz2lxoifJiIe5c/w640-h330/1_X1KvfsDJrYRoeNoZhTAFgg.jpg)
Conclusion:-
With the help of the amazon CLI package from the command prompt, we have launched an amazon EC2 instance and also we have applied all the necessary concepts.
Thanks! to Mr. Vimal Daga for Teaching us such a great thing.
No comments