Interacting With Amazon Web Services(AWS) using AWS CLI
Amazon Web Services (AWS) is the world’s most widely accepted cloud platform. Now, most of the industry started using cloud services so that they can focus on their business rather than worrying about infrastructural set-up as it's completed managed by cloud providers.
Cloud is about how you do computing, not where you do computing |
There are many ways available to login into the AWS cloud one of the easiest ways is using the AWS management console(WebUI) but there are many limitations with the AWS console, let's say if we want to launch 15 different types of instances with the different configuration so we have to launch every instance manually using management console but these problems can be resolved using CLI. we can do this task with a single line of code with AWS CLI.
So what is AWS CLI?
AWS Command Line Interface (CLI) is a tool to manage your AWS services using Command Prompt. Using just a single tool we can download and configure and can control the entire AWS cloud and by this, we can also surpass many limitations that came across when we use WebUI of AWS.
In this article, we would be setting up an EC2 instance by creating a new key-value pair and security group using CLI. Then we would be attaching an EBS storage to our running instance.
Creating a key-pair using CLI
A key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance.
the command to create a key-pair is:
AWS key-pair comes under ec2 services in AWS so we first have to specify the command or the service we want to access. “create-key-pair” is the subcommand or one of the features of the ec2 service and “key-name” is the option or property we specify for the feature we are using and “ec2_key” is the name of the key being created.We have successfully created a keypair and we can also check whether the key-pair is created or not using AWS console or GUI.
Creating a Security Group using CLI
A security group acts as a firewall for your EC2 instances whose work is to control incoming and outgoing traffic between instance and Network.
For creating a security group we use the command:
Security Group is also a part of EC2 and create-security-group is the subcommand to create a new security group and “group-name” is the feature to provide a name to security group as we did by giving “my_security” name and after running this command we get our created security group id.
Creating an EC2 instance:
An EC2 instance is a virtual server in Amazon’s Elastic Compute Cloud (EC2) for running applications on the AWS infrastructure.
We will use the same security group and key which was created to launch this new instance
By this command our new instance(OS) is launched whose image-id is the id of Amazon Linux 2 AMI, in this, we only require 1 CPU and 1 Gb RAM so we have used the t2.micro type which is available in the free tier eligibility as well, the count tells we need to launch only 1 instance of the same configuration and we used subnet id of Mumbai availability zone ap-south-1a.
Creating the EBS volume and attaching with a created instance:
EBS stands for Elastic Block Storage. The Amazon EBS volume is a solid, high-quality device that you can attach to your conditions. After volume up, you can use it in the same way that you can use a virtual hard drive. Flexible EBS values.
We have successfully created an EBS volume of size 1 GB from the above command and created it in the AWS Availability zone of ap-south-1a.
We purposely created this volume in the ap-south-1a Availability zone as EBS is the zonal service it can only be attached with the instance created in the same availability zone.
This command has attached this EBS volume to our created instance and volume-id is our EBS volume id, and instance-id is this id from which we want to attach our volume, device is the name of our volume.
Here from GUI also we can verify our volume is successfully attached with our instance.Conclusion:
We have completed our task and here are some observations while performing this task with the help of AWS CLI.
- AWS CLI is better and faster than AWS WebUI as on 1 click the entire system is launched.
- Once we come to about basic commands of CLI, we can easily operate AWS services.
And for more information on AWS CLI, you can visit here
Thanks for reading this article! Leave a comment below if you have any questions.
Comments
Post a Comment