Launching AWS Instance with CLI
Task Description:
🔷 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.
Prerequisite:
- We need to install the Aws cli program you can install it from here
- Now when we have installed the program we need to authenticate yourself so that we can use our AWS Account for this purpose we use “aws configure” command
- Enter your Access key , security key and region so that we can access the account
C:\Users\gaura>aws configure
AWS Access Key ID [****************CNVX]:
AWS Secret Access Key [****************aeFy]:
Default region name [ap-south-1]:
Default output format [None]:
Let’s Begin
🔰 Create a key pair
First we will create a key-pair with the name Key_cli
aws ec2 create-key-pair --key-name Key_cli
🔰 Create a security group with the name CLI-SG and giving the description is must here I have gave it as created-over-cli
aws ec2 create-security-group — description created-over-cli — group-name CLI-SG
we can also add the firewalld rules over the Security Group
Let’s Check
🔰 Now we will Launch an instance using the above created key pair and security group.
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --count 1 --subnet-id subnet-8ad2e8e2 --security-group-ids sg-01f40659fc854126b --key-name Key_cli
Let’s Check the Instance required info
🔰 Create an EBS volume of 1 GB.
aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp2
🔰 The final step is to attach the above created EBS volume to the instance you created in the previous steps.
aws ec2 attach-volume --device /dev/xvdb --instance-id i-058afe3aa84b04a1b --volume-id vol-0a0915d729284f341
So now we have we have successfully performed the task 🎖🎖🙌
💎Lets Clean the environment
So we have to detach the volume we attached, Delete that volume, Terminate the instance launched and at the last delete the security group and the key-pair