Building Cloud Infrastructure Using AWS CLI

Pranita Gughane
4 min readMay 11, 2021

--

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.

🤔Why AWS CLI?

AWS CLI gives you the ability to automate the entire process of controlling and managing AWS services through scripts. These scripts make it easy for users to fully automate cloud infrastructure. Prior to AWS CLI, users needed a dedicated CLI tool for just the EC2 service.

✅TASK DESCRIPTION:

📌 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.

💥Installing AWS CLI :

Installation of AWS CLI is so simple. You just need to download the application from the below mentioned link and like we install any other application, just run the application and keep on clicking and it will be installed.

✔Check if it has installed properly :

aws --version

💥Configuring AWS CLI :

Before starting, we need aws access key and secret key for configuration. Because for humans we use username and password for authentication. But to authenticate any program we use access key and secret key.

  • To, get those things you need to go to your AWS account from AWS Web Console. Then go to “IAM” service => click on “Users” => then click on “Add User” and create one user.
  • Then click on “Programmatic access” and if you read the description of this access you can see, it’s giving us “access key” and “secret key”. For reference follow the below mentioned screenshot…
  • Next click on “Tags” and give any desired tag. Then click on “review” and then click on “Create User”. Next it will provide you one option to see your Access Key and Secret Key. Don’t forget to “Download” the credentials by clicking on the download button for future reference.

Step 1:Login to AWS Using security credentials of IAM User we created .

aws configure

Step 2: Create a key pair

For creating Key Pair we have command as :

aws ec2 create-key-pair --key-name task1key

Step 3: Create Security group

To create Security group we have the following command :

aws ec2 create-security-group --group-name AWSgroup --description "my aws security group" --vpc-id vpc-78d61505

Step 4: Launch one EC2 Instance using above Key pair and Security Group

To launch ec2 instance AWS CLI has command as :

aws ec2 run-instances --instance-type _type_ --image-id ami_id --key-name key_name --security-group-ids   group_id  --count no_of_instance --subnet-id

Step 5: Create one EBS Volume and attach it to the EC2 Instance we launched

To Create EBS Volume AWS CLI has command as :

aws ec2 create-volume --volume-type volume_type --size volume_size --availability-zone AZ_name

Step 6 : Attach EBS Volume to EC2 Instance

we have command :

aws ec2  attach-volume   --volume-id volume_id   --instance-id instance_id  --device device_name

Thank You for reading my Article!!!😊

--

--