✴️ I will tell my AWS that I want to use the ec2 service and in this service I want to create the security group and the name of the group is rohan and the description is aws cli task security group
✴️ After Running this Command it Created the Security Group and gave me the security group id in output and i have stored it in security.text
✴️ But Here We have 1 problem:-
inbound rules are not created in Security Group.
because by default the upper command create the outbound rule only. it does not create the inbound rule and in this command they didnt provide us the option to add the inbound rule.
Then How to Add Inbound Rule?
I have Used the below command to add the inbound rules to the security group
aws ec2 authorize-security-group-ingress --group-name rohan --cidr 0.0.0.0/0 --protocol all
✴️ I will tell my AWS that I want to use the ec2 service and in this service I want to add the ingress rules in security group and the security group to which I want to add ingress rules that security group name is rohan and the protocol at which I allow the traffic is all. I want to allow the traffic at all the ports and “ — cidr 0.0.0.0/0” means that I want to allow all the traffic.
✴️ Then wait for 2 seconds and set a variable and store the security group id in it with the help of security.text file
timeout 2 set /p variable1=<security.text
🔰 3. I Have Launched The Instance:-
✴️ I have launched the instance and here i have passed the variables to make it more dynamic
✴️ I will tell my AWS that I want to use the ec2 service and in this service I want to run the instance and the image id which I want to use is “ami-03cfb5e1fb4fac428” the instance type I want to use is t2.micro and add the security group whose id is stored in the %variable1% (which we have created previously) and the key pair which I want to use that keypair name is rohan4.
✴️ The output of this file will store in the instanceid.text.
✴️ Then Set the variable and store the instance id with the help of instanceid.text file in which we have stored the instance id. and then wait for 30 second.
✴️ So our instance can come in running state and we can perform ssh in it.
set /p variable=<instanceid.text timeout 30
✴️ With this command I will find the Publicdnsname so i can do ssh and then i have stored it in Name.text
✴️ From the Name.text the PublicDnsName has been copy in the variable
aws ec2 describe-instances --query Reservations[-1].Instances.[PublicDnsName] --output text > name.text
set /p name1=<name.text
🔰4. I Have Created The EBS Volume Of 1GB:-
✴️ I will tell my AWS that I want to use the ec2 service and in this service I want to Create the volume in the ap-south-1a availbility Zone and the size of the volume should be 1 GiB.
✴️ I will store the volumeid in the pop.text and then wait for 10 seconds
✴️ Here the %name1% is the variable which stores the PublicDnsName of the instance and the %key% is the variable which stores the key name and here I am running the command to install the httpd software for the webserver