What is AWS ?

Amazon Web Services is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis.

Why AWS ?

Amazon hosts their data centers across the world, allowing users to choose where they want their data and applications to live. By offering more than 30 availability zones, AWS lets you run your technology right where your users are accessing it, resulting in a measurable performance boost.

What is 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.

What We are going to perform in this tutorial :

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 EBS to instance created in step 3.

First we need to install AWS CLI on local system :

You can download CLI installation Binary from here .

Installation steps are shown below :

We first need an AWS account to perform this , You can create one here.

Now We need to create one IAM User for creating keys , and generate keys

You can find guide to do this here.

let’s get started :

verify AWS CLI :

aws --version

You will get output like :

aws-cli/2.1.4 Python/3.7.9 Windows/10 exe/AMD64

Run :

aws configure

Put your Keys when asked :

aws configure
AWS Access Key ID [None]: AKXAXX6XXXXXXXXXX
AWS Secret Access Key [None]: vgXXSXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: us-west-2
Default output format [None]: txt

Create a Key Pair :

aws ec2 create-key-pair --key-name aws_task3

You will get key pair :

aws ec2 create-key-pair --key-name aws_task
5c:7a:0b:e2:7f:c2:ee:a4:60:1e:cd:44:42:e8:84:74:e2:47:9f:cb -----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAvpV+sAbwhqVeOKegUZ8CC91JjbHL+c8O3M/oAFAMllCjylFW
5K1IZ1LfFzdwUsn2iPZSu+wfLgXF5Jo3Gm4uDFfjSFl84Aej5PqxL8/K6v2Ej9Q0
kzT3kFopumfvPyYEsSwOVqD1+PS5i08VX1PCgQKOak4GuPe6EDmr8TSNIAjslSNR
5rlyjv2gAkckmo8MbCRMlpLN2vYHHAPGKOfQx6dwmWpCRsFLZI0lKmTEBT0wxHkd
bmi6qyjDqPLHJzdUJCAhv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HLEL8Ejr9UtqAD+L3Bw9/Bil1RDUgO53U7Nw
3VhSrGUCf02zPHlFfTNy5/z3GlL/BY6sifr7Hie7APwaDnx0j9obw7jMzCzghu6C
wDA83s+ZvksI+1AzSklBx7tOfmfO+pPqIW1zAIBIjAfQB1WB8zLVjdUslKv+TiR4
5kTTTCDrpGNC0KsWwnb5t6dunCy1IecO6H9or0A8ftFhCnQDdqk=
-----END RSA PRIVATE KEY----- aws_task key-0be0dfd7866e45c

Create a security group

aws ec2 create-security-group --description "This is Task3 Security group" --group-name Task3_SGOUTPUT : sg-05bXXXXXXXabd58

Launch an instance using the above created key pair and security group

You will need :

Instance ID

Image ID : Default AMI for ubuntu => ami-07a0da1997b55b23e

Key Name

Subnet ID

Security Group (id with sg)

aws ec2 run-instances --image-id ami-07a0da97b55b23e --instance-type t2.micro --key-name aws_task3  --security-group-ids sg-05bXX692f99abd58  --subnet-id subnet-139304e --count 1OUTPUT :  820205001403    r-0c4b7a32706c397c1
INSTANCES 0 x86_64 744e38-46be-43-9c7dfa43f450f568 False True xen ami-07a0da17b55b23e i-0e8ed175057c41ade t2.micro aws_task3 2020-11-25T9:04:10+00:00 ip-172-31-13-6.us-west-2.compute.internal 172.31.13.6 /dev/xvda ebs True subnet-13304e hvm vpc-23410d5b
CAPACITYRESERVATIONSPECIFICATION open
CPUOPTIONS 1 1
ENCLAVEOPTIONS False
METADATAOPTIONS enabled 1 optional pending
MONITORING disabled
NETWORKINTERFACES interface 0a:64:77:cd:f1:8d eni-07643a15ff6e66ca2 820205001403 ip-172-31-13-6.us-west-2.compute.internal 172.31.13.6 True in-use subnet-1398304e vpc-23410d5b
ATTACHMENT 2020-11-25T09:04:10+00:00 eni-attach-02fa006fd15778e90 True 0 0 attaching
GROUPS sg-05b6a9692f99abd58 Task3_SG
PRIVATEIPADDRESSES True ip-172-31-13-6.us-west-2.compute.internal 172.31.13.6
PLACEMENT us-west-2c default
SECURITYGROUPS sg-05b6a9692f99abd58 Task3_SG
STATE 0 pending
STATEREASON pending pending

Create an EBS volume of 1 GB.

Create EBS Volume in same zone that our instance have launched :

aws ec2 create-volume --availability-zone us-west-2c --volume-type gp2 --size 1OUTPUT : us-west-2a      2020-11-25T09:06:57+00:00       False   100     False   1               creating        vol-078b8d1a3530d0   gp2

Attach the above created EBS volume to the instance you created in the previous steps

aws ec2 attach-volume --device /dev/xvdb --instance-id i-0e8edXXX7c41ade --volume-id vol-0ac486XX14d3959OUTPUT : 2020-11-25T09:09:24.806000+00:00        /dev/xvdb       i-0e8ed17505XXXade     attaching       vol-0ac48314d3959

That’s it…

This tutorial is over here, You can explore more commands in aws cli documentation.

Thanks.

Helping Businesses to Build online Presence