Getting Started with AWS-CLI
aws CLIv2: Installation, Configuration and basic operations in Windows command prompt
Initially as a beginner in aws cloud we use graphical Console (WebUI provided by aws) for high level understanding. As we step ahead, in real industry case, instead of manual part (which is time consuming) we have to be very fast in terms of performance, minimizing time and manpower i.e. to achieve automation. And for automation aws console won’t help, here CLI (Command Line Interface) plays major role.
aws CLI is a command line interface tool from which we can control and perform multiple aws operations and ultimately automate whole aws part with scripts.
Install and Configure aws CLI:
Download and install aws cli latest version 2 : download link
Before configuring aws cli, first open terminal/command prompt and check version to cross check if it is installed properly -
To configure aws cli, we must have user account (aws access key and secret key). So if you don’t have user with programmatic access, create one from aws console.
Creating User for programmatic access:
Go to IAM service and “add user”-
Give user name, access type- Programmatic access (programmatic access is required for cli, apart from it we can also enable console access)
set permission accordingly, here I have given ‘PoweUserAccess’ -
finally, here we get user credentials. This is first and last time we can get it so download and save csv file.
Configuring aws cli:
here give generated access key and secret key and enter for by default setting
For the demonstration of aws CLI, we will launch one instance. We are going to perform following steps using AWS CLI:
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️⃣ Attach the above created EBS volume to the instance
General format of aws command- Every command starts with ‘aws’, then service followed by operation to perform and it’s options. Most of the commands has required options to be given. All this you can check in documentation provided by aws- https://docs.aws.amazon.com/cli/
1️⃣Creating a key pair:
To launch instance we must have key pair.
here output text option will save generated key as given file type as .pem. We can check with aws console by root user
2️⃣ Creating a security group:
For an instance we must define security group
by default it will set outbound to all traffic and no inbound. According to our requirement we can set inbound rule ex. for ssh login. We have to give protocol name, port no. and cidr range.
3️⃣ Launching instance using the above created key pair and security group:
For launching instance, we need to give ami id that we can obtain from console, count as no. of instance, instance type, key name and security group id. We can also give any tag to it ex. Name
4️⃣ Creating an EBS volume:
To create new volume, mention volume type and size as we require along with availability zone. Here we have to attach this volume to above launched instance so we must create this volume in same zone as instance.
5️⃣ Attaching the above created EBS volume to the instance:
To attach created volume to instance, mention volume id and instance id to which you want to attach volume along with device name.
☁ Extra Bonus
We have attached external volume to instance. But in order to use it we must perform 3 steps- Make partition, Format and Mount. Without these 3 steps, we can’t use volume.
🔑ssh login to instance: with default ec2-user and attached key. Switch user to root for admin access.
here we can see external volume disk /dev/xvdf is attached but not is use.
💽Formatting and mounting:
here disk is formatted and it is mounted on new folder ‘/vivek’ and now it is ready to use!
PS: This is the task from a ongoing ‘AWS-CSA Training’ and I am thankful to Mr. Vimal Daga Sir for their valuable guidance.