AWS CLI
What is AWS??
Amazon Web Services (AWS) is a secure cloud services platform, offering compute power, database storage, content delivery and other functionality to help businesses scale and grow. Running web and application servers in the cloud to host dynamic websites. With AWS, we receive a virtual environment that lets us to load the software and services that our application requires.
Benefits:
1) Easy to use:
AWS is designed to allow application providers, ISVs, and vendors to quickly and securely host our applications — whether an existing application or a new SaaS-based application. We can use the AWS Management Console or well-documented web services APIs to access AWS’s application hosting platform.
2)Flexible:
AWS enables us to select the operating system, programming language, web application platform, database, and other services that we need. With AWS, we receive a virtual environment that lets us to load the software and services our application requires.
3)Cost-Effective:
We pay only for the compute power, storage, and other resources that we use, with no long-term contracts or up-front commitments.
4)Scalable and high-performance:
Using AWS tools, Auto Scaling, and Elastic Load Balancing, our application can scale up or down based on demand. Backed by Amazon’s massive infrastructure, we have access to compute and storage resources whenever we need them.
5)Secure:
AWS utilizes an end-to-end approach to secure and harden our infrastructure, including physical, operational, and software measures.
We have 3 ways to interact/communicate with AWS Technology i.e
1)Using WebUI: In this we can access the AWS services through Web portal that is by Graphical Interface where we can click and select operations using Mouse.
2)Using CLI (Command Line Interface):For this we have to install one software i.e AWS CLI SDK Tool in our base OS
3)Using Automation i.e by writing program/code
What is AWS CLI??
The AWS Command Line Interface (AWS CLI) is an open source tool that enables us to interact with AWS services using commands in our command-line shell. With minimal configuration, the AWS CLI enables us to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in our terminal program
Installation Setup:
First go to the link as per your base OS
- (For Windows): https://awscli.amazonaws.com/AWSCLIV2.msi
- (For Linux): https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip
- (For Mac): https://awscli.amazonaws.com/AWSCLIV2.pkg
In my case I am using Windows as a base OS
Now, after this go to following steps:
Now ,after this firstly we have to go to our windows command prompt and run the aws command for checking that the software is install or not
We see that our AWS CLI Tool is successfully install in our base OS
TASK OBJECTIVE:
- Create a KEY-PAIR using CLI
- Create a Security-Group using CLI
- Launch an EC2 Instance using the above created KEY-Pair and Security Group
- Create an EBS Volume of 1 GB
- Finally, we have to attach the above created EBS volume to the Instance i.e created in step 3
Lets first understand some of the basic terminology i.e
IAM:
AWS Identity and Access Management (IAM) is a web service that helps us to securely control access to AWS resources. We can use IAM to control who is authenticated (signed in) and authorized (has permissions) to use resources.
KEY-PAIR:
A key pair, consisting of a private key and a public key, is a set of security credentials that we use to prove our identity when connecting to an instance. Amazon EC2 stores the public key, and we can store the private key. We can use the private key, instead of a password, to securely access our instances.
SECURITY-GROUP:
A security group acts as a virtual firewall for our instance to control inbound and outbound traffic. When we launch an instance in a VPC, we can assign up to five security groups to the instance.
If we launch an instance using the Amazon EC2 API or a command line tool and if we don’t specify a security group, the instance is automatically assigned to the default security group for the VPC.
EC2 INSTANCE:
Amazon Elastic Compute Cloud (Amazon EC2) is web service that provides scalable computing capacity in the Amazon Web Services (AWS) Cloud. Using Amazon EC2 eliminates our need to invest in hardware up front, so we can develop and deploy applications faster. We can use Amazon EC2 to launch as many or as few virtual servers as we need, configure security and networking, and manage storage. Amazon EC2 enables us to scale up or down to handle changes in requirements or spikes in popularity, reducing our need to forecast traffic.
EBS VOLUME:
An Amazon EBS(Elastic Block Size)volume is a durable, block-level storage device that we can attach to our instances. After we attach a volume to an instance, we can use it as a physical hard drive. EBS volumes are flexible.
We can use EBS volumes as primary storage for data that requires frequent updates, such as the system drive for an instance or storage for a database application. We can also use them for throughput-intensive applications that perform continuous disk scans. EBS volumes persist independently from the running life of an EC2 instance.
We can attach multiple EBS volumes to a single instance. The volume and instance must be in the same Availability Zone.
Lets start the practical:
To use AWS Cloud Services we first required to Login with the AWS Account .Here we are using AWS CLI for Login to AWS Account through a Windows CLI so for this we have to create one IAM User whose credentials (Access Key and Secret Key) are used to communicate/interact with the AWS Cloud instead of creating Root user .
For Creating IAM USER Follow these steps:
1st go to AWS Cloud then follow the steps shown in image,
Click on Add User for add new user
Now, give any User name in my case I am giving as awsnewuser and then select Programmatic Access that provides us an access key and secret key
Now, Click on Attach existing policies directly and then select the AdministratorAccess to provide the access to user.
Now, give the tag to the IAM User in my case I am giving an key as a Name with Newuser as a value and then click on Review.
click on Create user
Then click on Download.csv and download it
Now , we see that we successfully create an user with name newuser
Now , after creating user we can Login to AWS Using security credentials of IAM User . To Login to AWS Cloud through AWS CLI we have to run command aws configure in windows CLI. After running these command once we have to give AWS Public and Secret Access key and default Region name .This command helps us in login to the AWS via CLI .
Now we successfully Login to AWS Account
1) Now, we have to create an KEY-PAIR
We see that in my AWS I have already 2 key exist i.e hadoopkey and keyhadoop
Now, If we want to create new Key Pair using CLI we can use command :
and we see that in AWS a New key is successfully Created with name newkey1
To see all the Key-Pairs exist in that particular region using CLI we use command
2) Create an Security-Group
We see that in my AWS I have exist 9 security groups
Now, if we want to create one more new security group using CLI we can use the command
And we see that in AWS a new security group is successfully created with the name mysecurity
We see that in our security group there is no inbound rules exist
So to Set Inbound or Ingress Rule to a security group so that we can authorize the outside traffic we can use the command
Now, we see that we have created one inbound rule successfully
To see the above all Information about Security Group and see all the existing security group using CLI we use command
3) Now, we have to launch an EC2 Instance using the Key-Pair and the Security Group that we have created in the above previous steps.
We see that in my AWS I have already exist with 3 instances
Now, if we want to launch one more EC2 Instance using CLI we use command
Now, if go to our AWS and we see that there is one more instance is launch and it is in running state
4) Now, after Launching EC2 Instance now we have to create one EBS Volume of 1 GB
In AWS we have already exist with 4
Now if we want to create one more EBS Volume of 1GB in AWS using CLI we use the command
Now, we see that we have successfully created volume of 1 GB
5) Now, Finally we have to attach the EBS Volume to the EC2 Instance that we created in the previous steps.
Initially, in our EC2 Instance we see that we have only 8 GB storage available
Now, if we want to attach our EBS Volume to this EC2 Instance using CLI we use command
And now if we go to our AWS and see that in our instance there is 1 GB EBS volume is attached Successfully
Thankyou!!
For any queries and suggestions,feel free to dm me!!