AWS Command Line Interface
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.
Description of Task:
- Create a new key pair.
- Create a Security group.
- Launch new EC2 instances using the created key-pair and security group.
- Create an EBS volume of 1GB.
- Attach the Storage/EBS volume to the launched instance.
SOLUTION:
STEP1:
Firstly we have to configure our AWS credentials by using the given command.
aws configure
STEP2:
now we create a keypair by using the given command.
aws ec2 create-key-pair --key-name "mytaskkey"
STEP3:
now we create security group by using given command.
aws ec2 create-security-group --group-name myawssg --description "Allow SSH"
To set ingress rule we use the given command.
aws ec2 authorize-security-group-ingress --group-id sg-033ce882b7810cc26 --protocol tcp --port 22 --cidr 0.0.0.0/0
STEP4:
we can also see the complete description about the security group by using given command.
aws ec2 describe-security-group --group-id sg-033ce882b7810cc26
STEP5:
now we launch the instance by using the given command.
aws ec2 run-instances --image-id ami-0e306788ff2473ccb --instance-type t2.micro --key-name mytaskkey --security-group-ids sg-033ce882b7810cc26 --count 1
STEP6:
Now we create the EBS Volume by using given command.
aws ec2 create-volume --availability-zone ap-south-1a --size 1 --volume-type gp2
now we attach the volume that we created to the instance by using the given command.
aws ec2 attach-volume --volume-id vol-0ec58f68411f43e16 --instance-id i-05c8b0cb7eda8db9e --device /dev/sdh
STEP7:
In the last ,we detach the volume by using given command.
aws ec2 detach-volume --volume-id vol-0ec58f68411f43e16
And then terminate the instance by using the given command.
aws ec2 terminate-instances --instance-ids i-05c8b0cb7eda8db9e