AWS CLI
What is AWS CLI?
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.
Why do we need AWS CLI?
AWS CLI gives you the ability to automate the entire process of controlling and managing AWS services through scripts. These scripts make it easy for users to fully automate cloud infrastructure. Prior to AWS CLI, users needed a dedicated CLI tool for just the EC2 service.
How to login through AWS CLI ?
To login through AWS CLI you need access key and secret key. We can get both of them by creating IAM user.
Further give username, give programmatic access and create custom password.
Select user policy as poweruseraccess.
Further give tags and click on create user. Then you will get access key and secret key.
Now go to command line and type following commands
aws configure, then further give access key , secret key , region name and output format.
Now we have logged in our aws account through cli.
Our task is:
1.Create a key pair
2.Create a security group
3. Launch an instance using the above created key pair and security group.
4. Create an EBS volume of 1 GB.
5. The final step is to attach the above created EBS volume to the instance you created in the previous steps
1.To create key pair command:
aws ec2 create-key-pair --key-name taskkeypair
We have created a key pair with name taskkeypair.
To check it is created or not you can verify it from webui.
2. Create a security group
To create a security a group using cli we use following command:
aws ec2 create-security-group --group-name tasksecuritygroup --description "for task"
To verify it we can check through webui.
3. Launch an instance using the above created key pair and security group.
To launch instance , select image ie type of os you want to launch redhat, windows etc, select number of os , select datacenter ie subnet id , select security group and key pairs.
command: aws ec2 run-instances --image-id ami-052c08d70def0ac62 --instances-type t2.micro --count 1 --subnet-id subnet-196a0155 --key-name taskkeypair --security-group-ids sg-0054aab75db9e099e
To verify again you can go to webui and verify.
4. Create an EBS volume of 1 GB.
To create volume you have to select volume type , specify size of storage and select datacenter.
command: aws ec2 create-volume --volume-type gp2 --size 1 --availability-zone ap-south-1b
Go to webui and check volume id to verify.
5. The final step is to attach the above created EBS volume to the instance you created in the previous steps.
To attach EBS volume to instance through cli you need to give volume id ,instance id and device name.
command: aws ec2 attach-volume --volume-id vol-0b2233821085ce424 --instance-id i-06217cc805d3693e3 --device /dev/sdf
To verify go to webui .
Thank You!!!