Hello Readers! In this we will see how to launch an EC2 instance from the command line using AWS CLI. Before starting you must have AWS CLI installed on your machine and AWS must be configured.
So, let’s start!
Step1 : Install AWS CLI and AWS must be configured on your system. To check it use the following command.
Step2 : Create your key-pair from the command line.
Now, key-pair is created. For checking it use the following command:
Step3 : We will create a security group. For this we need vpcs id use this command and copy that id for further use.
Use the following command to create a security group.
Check it here.
Check it from the command line also.
Step4 : Add a rule that allows inbound SSH traffic. Before this checkip and copy this.
Use the following command for this.
Step5 : Create an ec2 instance. For doing this we need ami-id, security group id, subnet-id and key-pair name. Use the following command for creating ec2 instances. Edit this command as per your ids.
You will see the status of the instance pending.
You will find here also that instance is created and its initializing. I will take 2 minutes to get in running condition.
After some time its state is running. It has passed all the status checks.
Step6 : Login to this instance. For this we need a public ip address. Firstly change the permission for the keypair by using this command.
Delete AWS EC2 instance using AWS CLI:
Now, what if we want to delete EC2 instances by using AWS CLI. So, for this we have to firstly delete the key-pair use the following command:
Secondly we need to delete ec2 instances. Paste your instance-id in the following command.
Finally we can delete the security group id.
We are all done now!
So, In this blog we saw with a few easy steps how we can launch ec2 instances using AWS CLI. Thanks for being with me till the end. If you find this blog helpful do share with your friends.