Getting started with AWS CLI 🧐
Launching key pair, security group, instance ,creating and attaching EBS volume using AWS CLI
What will we see in this blog….🤓
🔅 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.
First Let’s learn what is AWS CLI :
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.
INSTALLING AWS CLI :
The AWS Command Line Interface (AWS CLI) is available in two versions.
The AWS CLI version 2 is the most recent major version of the AWS CLI and supports all of the latest features.
We can install AWS CLI using following link:
CONFIGURING AWS CLI :
For using AWS CLI we have to first configure it using “aws configure” in which we have to provide “access key” and “secret access key” for providing keys We have to create AMI user with AWS Management console access. Inside create policy we have to give this user “power access” that is… the user can access everything except IAM and billing dashboard.
Key Pair :
Key Pair is set of security credentials that you use to prove your identity when connecting to an instance.
Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances. Anyone who possesses your private keys can connect to your instances, so it’s important that you store your private keys in a secure place.
We can create key pair using AWS CLI using following command:
aws ec2 create-key-pair --key-name MyKeyPair --query 'KeyMaterial' --output text | out-file -encoding ascii -filepath MyKeyPair.pem
To create a key pair, use the create-key-pair command with the --query
option, and the --output text
option to pipe your private key directly into a file.
For PowerShell, the > file
redirection defaults to UTF-8 encoding, which cannot be used with some SSH clients. So, you must convert the output by piping it to the out-file
command and explicitly set the encoding to ascii
.
SECURITY GROUP :
A security group acts as a virtual firewall for your instance to control inbound and outbound traffic.
Inbound traffic refers to information coming-in to a network.
Outbound traffic refers to information going-out of a network.
In order to connect to our instance using SSH we have to add SSH rule in inbound rules for our security group
aws ec2 authorize-security-group-ingress --group-id sg-03a0cf71b131caa72 --protocol tcp --port 22 --cidr 172.31.0.0/16
LAUNCH INSTANCE :
We will launch instance with the key pair and security group we created above using AWS CLI
We can add tags to our instance :
our instance will look like this after naming:
CREATE EBS :
An Amazon EBS volume is a durable, block-level storage device that you can attach to your instances. After you attach a volume to an instance, you can use it as you would use a physical hard drive. EBS volumes are flexible.
You 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. You 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 will create 1 GiB EBS volume with name tags EBS_CLI as follows :
ATTACHING EBS VOLUME :
In order to use EBS volume we have to attach it to our instance using instance ID as follows :
Conclusion :
We have successfully created Key Pair, Security Group, an instance using kry pair and security group we created , EBS volume and finally attaching EBS volume to our launched instance. 🥳
In order to mount EBS volume to our instance you can refer to following article:
Let me know if you find this article helpful… Your feedback is valuable and it will help me improve… clap if you like it.👏❤️