Accessing AWS using CLI
Problem Statement
Create a key pair
Create a security group
Launch an instance using the above created key pair and security group
Create an EBS volume and attach to the instance we created above
All the above steps must be performed using AWS CLI
Overview
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.
To use AWS Cloud through CLI only Prerequisite is to Install the AWS CLI SDK tool.
Now let’s use AWS CLI, for this, we have to download AWS CLI in our base os.
From this page, we can download the AWS CLI.
Now let’s give AWS credentials, for this we need the access key and secret key these we will get while creating an IAM user in AWS.
aws configure
#to check whether we logged in
aws configure list
CREATING KEY PAIR
Now we successfully Logged Into the AWS Account. After these, We have to create a Private Key to connect to the ec2 Instance. For creating Key Pair we have command as :
aws create-key-pair --key-name key_name
CREATE SECURITY GROUP
To create a Security group we have the command as :
aws ec2 create-security-group --group-name group_name --description "_description_"
We can also see the Information about Security Group in CLI using the command :
aws ec2 describe-security-group --group-id security_group_id
CREATE INSTANCE
Now we have to Launch one EC2 Instance using the above Key pair and Security Group. To launch ec2 instance AWS CLI has command as :
aws ec2 run-instances --security-group-ids group_id --instance-type _type_ --image-id ami_id --key-name key_name --count no_of_instance
After Launching EC2 Instance now we have to create one EBS Volume and attach it to the EC2 Instance we launched.
CREATE EBS VOLUME
To Create EBS Volume AWS CLI has command as :
aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name
To Attach EBS Volume to EC2 Instance we have command:
aws ec2 attach-volume --volume-id volume_id --instance-id instance_id --device device_name
For getting the Information of EC2 Instance AWS CLI has command as :
aws ec2 describe-instances
To get the output of the command in other formats we have to use — output parameter. In my case, I use the YAML format.
aws ec2 describe-instances --output
To Terminate the EC2 Instance use command :
aws ec2 terminate-instances --instance-ids instance_id
let's see if they are created in my AWS account
you can see that all of them are created in my account
Thanks for reading!
Connect me on my LinkedIn as well.