AWS Command Line Interface
Hasti Vora
|| RHCE Certified || QA Engineer || Automation Enthusiast | Playwright & Robot Framework |
Amazon Web Services (AWS) is the world’s most comprehensive and broadly adopted cloud platform, offering over 175 fully featured services from data centers globally.
- 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.
We can use AWS services from three of the following ways:-
- WebUI
- Command Line Interface (CLI)
- Automation through scripts
Why use AWS CLI?
- In WEBUI we cannot launch two instances at different subnets at same time. [ There are many more such cases this is just an example ]
- CLI is automatable
- Real developers don’t use GUI !
YOU CAN VISIT HERE TO GET MORE INFO - AMAZON CLI
YOU CAN GET HELP FROM CLI FOR ANY COMMAND -
USING --->>> aws help , aws <command> help , aws <command> <subcommand> help
few examples:- aws ec2 help, aws ec2 describe-instance help
So we will perform a task wherein we will
?? Create a key pair
?? Create a security group
?? Launch an instance using the above created key pair and security group.
?? Create an EBS volume of 1 GB.
?? The final step is to attach the above created EBS volume to the instance you created in the previous steps.
To perform this task first we need to follow few steps:
- Create AWS account
- Install AWS CLI (version 2)
- For Windows you can use this link → AMAZON CLI V2 FOR WINDOWS
- Open Control Panel run command aws --version (For confirmation of installation)
- After all is set we need to go to AWS console to create user (We can also create user from CLI)
→ Go to all service → choose IAM and choose go to IAM Dashboard
Now you need to perform following task to create user.
- Select Users option from left sidebar in Dashboard and select add user.
2. Add username and password → Next Permission
3. Click attach existing policy -> select Power User Access
5. Click → Next Review → add user
6. You have to use this access key and secret key
7. Go to the command prompt and enter your credentials.
- You will need to enter here your access key and secret key
- You can choose availability zone and output format like - yaml , yaml-stream, table , json
Let us now start with the task
- create key pair
Command → aws ec2 create-key-pair --key-name keypair
2. Create security group with Inbound rule all traffic
Command → aws ec2 create-security-group --group-name security --description security
Command → aws ec2 authorize-security-group-ingress --group-name security --protocol all --cidr 0.0.0.0/0
3. Launch instance using above security group and key pair
Command → aws ec2 run-instances --image-id ami-0e306788ff2473ccb --key-name keypair --tag-specifications ResourceType=instance,Tags=[{Key=Name,Value=Hasti}] --security-groups security --instance-type t2.micro --placement AvailabilityZone=ap-south-1a --count 1
4. Create EBS Volume of 1GB
Command → aws ec2 create-volume --availability-zone ap-south-1a --size 1 --tag-specifications ResourceType=volume,Tags=[{Key=Name,Value=vol}]
5. Attach above created volume to instance
Command → aws ec2 attach-volume --volume-id vol-027d8476f1d155c31 --instance-id i-02d4ff604f947e5b8 --device /dev/sdf
So, in conclusion we have used AWS CLI to successfully launch instance. Once you have got idea of how to use it, its great tool believe me ! This is everything you will need to bring automation through your scripts and perform task which is not possible through WebUI.
!! THANKYOU !!
Site Reliability Engineer at Crest Data Systems
4 å¹´Very helpful!!
Software Developer @Infosys
4 å¹´Perfect
Learning Enthusiast let's Connect...
4 å¹´Fantastic...
World Record Holder | 2x TEDx Speaker | Philanthropist | Sr. Principal Consultant | Entrepreneur | Founder LW Informatics | Founder Hash13 pvt ltd | Founder IIEC
4 å¹´Grt
DevOps Engineer || Python || Docker || Ansible || Kubernetes || AWS || Jenkins || Buildkite || GoCD || GIT || GITHUB ||
4 å¹´Great work